• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Building JTree - Like Object

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !!
I would like to build an Object of class X which normally have a list of Child of class Y, but can also have Childs of class X.
Ex:
Object X
Object Y
Object Y
Object X
Object Y
.
.
Object Y
Object X
Object Y
Object X
Object Y
Object X
Object Y
The thing is Object X are only here to keep Object Y grouped together so of course the access methods have nothing in common....
Ex:
public class X{
public X(){}
// to get Object at position index
public ?? get(int index){}
// to remove object at position index
public ?? remove(int index){}
// to add an object in the list
public void add(??? object){}
// get the number of object in list
public int count(){ return count; }
....
...
..
.
}
public class Y{
public Y(){}
// to retreive object name
public String getName(){ return name; }

// to retreive object level
public int getLevel(){ return level; }
....
...
..
.
}
thanks in advance for any help !!
bye !
Nico
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could make a interface that both X and Y share:

Then your methods can return XorY.
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic