0

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.

  • 1
    It's an abstract method – ernest_k Dec 05 '19 at 17:15
  • 1
    That's not a variable declaration. That's defining a method signature for the interface which would need to be implemented by any class implementing the interface. – David Dec 05 '19 at 17:18

1 Answers1

2

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);
ernest_k
  • 44,416
  • 5
  • 53
  • 99