This discussion is archived
2 Replies Latest reply: Jun 12, 2010 8:26 PM by 843793 RSS

generics extends to 2 types

843793 Newbie
Currently Being Moderated
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>
  • 1. Re: generics extends to 2 types
    843793 Newbie
    Currently Being Moderated
    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
  • 2. Re: generics extends to 2 types
    843793 Newbie
    Currently Being Moderated
    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.