• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic question

 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want to do the following but I can't. I can only declare myGet() to return Object.

I can do this :



but it seems inelegant, as I have to repeat my declaration of the T parameter.
Is there a more elegant way?
 
Paul Clapham
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about this?
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"cannot resolve symbol E".
 
Paul Clapham
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(paying closer attention) Then what about this?If I understand your design, a TableRow<E> is a row that is encapsulated by an E object, not a row that contains E objects? In that case a SimpleTableModel<E> is going to encapsulate a list of TableRow<E> elements.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
unfortunately I need to access the class of TableRow too as I have a method :



 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want to do the following but I can't. I can only declare myGet() to return Object.

Why are you saying that?
I don't understand as it compiles perfectly "as is".
Also did a simple test with TableRow<Integer> and works fine.
Here is the code:

Regards
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Essentially I want to do this :

[/qb]<hr></blockquote>

but I cannot, I have to do this :



Which is repetition and not elegant, but it seems like it is the only way.

D.
[ May 16, 2006: Message edited by: Don Kiddick ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really need to care about which kind of TableRow the TableModel is using?

If you just want an add method,



should work just fine, shouldn't it?
 
Paul Clapham
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't understand why you need <E extends TableRow> anywhere. Are you going to be working with subclasses of TableRow -- or TableRow<X> -- in this class?
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do you really need to care about which kind of TableRow the TableModel is using?


The only reason I do is that I have a subclass of SimpleTableModel, called EditableTableModel which parameterizes TableRow with EditableTableRow.


I still don't understand why you need <E extends TableRow> anywhere. Are you going to be working with subclasses of TableRow -- or TableRow<X> -- in this class?

Both.

Here's the whole code :

TableRow :


EditableTableRow :


SimpleTableModel :


SimpleEditableTableModel:



thanks for all your input,
D.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, I don't think there is a way around

class SimpleTableModel<T, E extends TableRow<T>>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic