Forum Stats

  • 3,760,200 Users
  • 2,251,663 Discussions
  • 7,871,021 Comments

Discussions

generics extends to 2 types

843793
843793 Member Posts: 41,732 Green Ribbon
edited Jun 12, 2010 11:26PM in Generics
hi,
i have this class ReadFiletoLabelledRelationDiagonal, that read values from a file to a object.

how can i restrict the type of input, for example
ReadFiletoLabelledRelationDiagonal<? extends Integer>
and
ReadFiletoLabelledRelationDiagonal<? extends Double>

Comments

  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    Hello marciojc,

    if you want to express either an intersection type or a unsion type then I'm afraid neither is possible with the exception of type parameter bounds (which are allowed to be intersection types, i.e. <N extends Number & Comparable<N>>).

    With kind regards
    Ben
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    I'm not even sure I understand what your question is. Is Ben right in thinking you're looking for a union type? <? extends Integer/Double> is probably a bad example since both are final concrete classes, and so <? extends Integer> matches exactly Integer. Are you just looking for a ReadFileToLabelledRelationDiagonal<Number>?

    Maybe if you can say what you're trying to accomplish with a bit of code/pseudocode we can help you out. You haven't given enough information in your post for us to be of help.
This discussion has been closed.