27

Possible Duplicate:
Why would one declare a Java interface method as abstract?

I found the following code in one of our ejb interfaces. Does anyone know what the abstract does in the interface? If you do please also explain why it might be needed or provide a reference to read about it =)

@Local
public interface IDomasOrderProcessor {

    public abstract void executeOrderLines(List<OrderLine> lines);
    public abstract void setupJob(List<OrderLine> lines);
    public abstract void setupJob(OrderLine line);
}
Community
  • 1
  • 1
Marthin
  • 6,413
  • 15
  • 58
  • 95

4 Answers4

50

abstract is redundant in this case. All methods defined on an interface are public and abstract by definition.

Excerpt Java Language Specification section 9.4

Every method declaration in the body of an interface is implicitly abstract, so its body is always represented by a semicolon, not a block.

Every method declaration in the body of an interface is implicitly public.

Dev
  • 11,919
  • 3
  • 40
  • 53
  • 3
    So is "public", in this case, incidentally. Which is to say that you can drop both and it will do the same thing. It's possible that the code was originally an abstract class that got refactored. – Calum Feb 14 '12 at 13:29
  • 1
    Indeed, `public` as well. I added that to the answer, as my first was somewhat terse. – Dev Feb 14 '12 at 13:32
  • Since Java 8 interfaces can have methods with implementation. These are called default methods. Default methods can be added to an interface without affecting the classes that already implement the interface. – Stephan van Hoof Aug 09 '23 at 07:47
17

Both public and abstract modifiers are implicit in interfaces and should be avoided.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
6

A method in an interface is public and abstract by definition. I have heard some people say they feel that explicitly declaring them like that makes it clearer, but to me it seems like extra noise.

matt freake
  • 4,877
  • 4
  • 27
  • 56
3

As per this document all the methods of interface is public and abstract, so there is no mean to define explicitly abstract method inside the interface.

subodh
  • 6,136
  • 12
  • 51
  • 73