Search code examples
javainteger

Proper Usage of Parentheses in Variable Declaration


I'm trying to grasp a concept within Java programming and came across the following line of code:

int insertPerson(UUID id, Person person);

This code snippet is part of an interface named PersonDao. Within this interface, there's a method declaration insertPerson which takes two parameters: a UUID named id and an instance of the Person class named person.

Here's the interface for context:

public interface PersonDao {

    int insertPerson(UUID id, Person person);

    default int addPerson(Person person) {
        UUID id = UUID.randomUUID();
        return insertPerson(id, person);
    }
}

Could someone please provide a detailed explanation of the code line int insertPerson(UUID id, Person person);? How does this fit into the broader structure of the PersonDao interface and the addPerson method? Your guidance will be greatly appreciated.


Solution

  • It's an abstract public method with int as the return type, not a variable/property. PersonDao being an interface, it accepts abstract methods.

    Both public and abstract are implicit modifiers of the method. So it's equivalent to the following declaration:

    public abstract int insertPerson(UUID id, Person person);