File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes interfaces are strange... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interfaces are strange..." Watch "interfaces are strange..." New topic
Author

interfaces are strange...

Randy Smith
Ranch Hand

Joined: Mar 27, 2011
Posts: 44


Hi guys, I find that the concept of an Interface strange. Any method that live in an interface don't serve any purpose and doesn't do anything until it is implemented. If there are 10 guys using this interface, they could write that method in 10 different ways.

Why would anyone want an interface with no concrete methods at all other than a stop-gap multi-inheritance measure? I would appreciate if anyone could explain how can I fully exploit interfaces. Thanks!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

Look at it this way: The guru(interface) guarantees he will teach x stuff. How much is picked up, depends on the student.(concrete implementing class).

Randy Smith wrote:If there are 10 guys using this interface, they could write that method in 10 different ways.
True. but then these 10 classes are different. The interface has nothing to do with the implementation, just the contract (that the class will provide the functionality)


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37913
    
  22
But you can declare a MethodsLiveHere reference and use it, secure in the knowledge that it will have a placeholder() method.

You can create a List<E> reference, and assign an ArrayList<E> or a LinkedList<E> object to it, secure in the knowledge that if you ask whether it contains(someObject), that will work.
 
 
subject: interfaces are strange...
 
Similar Threads
Implicit properties of interface members...
Nikos Blog Overloading Question 58
interface relationships
Polymorphism and Automatic Failure
Abstract methods