001    package generics;
002    
003    public class Interval2<T extends Number, S extends Number> {
004            private T start;
005            private S stop;
006            
007            public Interval2(T start, S stop){
008                    this.start = start;
009                    this.stop = stop;
010            }
011            public T getStart(){
012                    return start;
013            }
014            
015            public S getStop(){
016                    return stop;
017            }
018            
019            public String toString(){
020                    return "[" + start + ", " + stop + "]";
021            }
022    
023            public double getLength(){
024                    return stop.doubleValue() - start.doubleValue(); 
025            }
026    
027            public static void main(String[] args) {
028                    Interval2<Integer, Double> int1 = new Interval2<Integer, Double>(0,10d);
029                    System.out.println(int1);
030                    System.out.println(int1.getLength());
031                    Interval2<Double, Integer> int2 = new Interval2<Double, Integer>(0.345d,10);
032                    System.out.println(int2);
033                    System.out.println(int2.getLength());
034            }
035    
036            
037    }