• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Looking for clarification on this: Object1 extends Object2<Object3>

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The extends is not an issue.
The question really pertains to Object3 in the brackets.
Is this a way to have Object2 extend Object3 since multiple inheritances can't be done?

public class Object1 extends Object2<Object3>.....

Any insight on what the above declaration implies???
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just like you do
public class Object1 extends Object2

you simply need to do
public class Object2 extends Object3

Manish
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, Objects don't inherit other objects. Classes inherit classes

Secondly, I think I'm not following your question. Do you mean whether you can have



Yes, nothing in Java will stop you from doing that. However, I don't know why you would do that.

It's much more common to do this with interfaces when you build a Proxy pattern



Here MyInterface is the interface, and MyClass implements an interface. Proxy class wraps an object of type MyInterface(called delegate), and also extends MyInterface. When you call the method on the proxy, it calls doBefore, then the method on the delegate then do After. THis allows you to "inject" behavior by extending Proxy



This kind of design is very common
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are correct in that what is listed as Object3 is an interface.

public class A extends TableRowSorter<TableModel>......
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are probably seeing an implementation of either a Proxy pattern, or a decorator pattern. Both patterns are very common
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tom Landry wrote:Yes, you are correct in that what is listed as Object3 is an interface.
public class A extends TableRowSorter<TableModel>......


But there's absolutely nothing to stop you doing it for something more specific if you want, eg:
public class BitMap extends HashMap<Integer, Boolean> { ...

(purely for illustration, you understand; I'm not sure it's the best idea )

Jayesh's example is simply a common pattern.

Winston
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic