• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in Generic Collection  RSS feed

 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I am beginner in java, and really appreciating great java API's however I find it hard to use Generic Collections.

First of all, I am using javafx and using its very popular collection, ObservableList.

I want to implement something like this:

*/


I will pass an argument like this:

*ObservableList<Brand> brandList
*ObservableList<Category> categoryList

in setList() method of my Maintenance class.

Note that Brand and Category are my model class each having different attributes.

To make it short I want my private ObservableList in my Maintenance class to handle the passed ObservableList whether it contains Brand or Category.

Thank you in advance!

Cheers! =)
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the Maintenance class to hold a generic list of an unknown type, then you're going to have to make your Maintenance class generic as well. So the Maintenance class gets a type variable, and you can use that for the list. For example:

Then the type is set when the Maintenance object is created. If the setList method is part of the MaintenanceInterface, then you're going to have to make that generic as well.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!