Java N-Tuple implementation

后端 未结 9 2408
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 16:53

I just made a Java n-tuple which is type-safe.
I\'m using some unconventional methods to achieve type-safety (I just made it for fun).

Can someone can give some

9条回答
  •  难免孤独
    2020-12-07 17:47

    If you're really interested in writing type-safe containers, look into generics:

    public class Tuple {
      private final T[] arr;
      public Tuple (T... contents) {
        arr = contents;  //not sure if this compiles??
      }
    
      // etc
    
      public static final void main(String[] args) {
        Tuple stringTuple = new Tuple("Hello", "World!");
        Tuple intTuple = new Tuple(2010,9,4);
      }
    }
    

提交回复
热议问题