2 Replies Latest reply on Jun 13, 2010 3:26 AM by 843793

    generics extends to 2 types

      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>
      ReadFiletoLabelledRelationDiagonal<? extends Double>
        • 1. Re: generics extends to 2 types
          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
          • 2. Re: generics extends to 2 types
            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.