`
trydofor
  • 浏览: 145679 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

Number 为何不 Comparable

阅读更多
现状 java 5+
package java.lang.Number
  public abstract class Number implements java.io.Serializable
package java.lang.Integer
  public final class Integer extends Number implements Comparable<Integer>


麻烦
* 直觉上 Number应该是可以 Comparable。
* 接受 Comparable<T> 的方法可以使用 Integer,有时 Integer被包成Number,就不能用了。

讨论
这样有啥不好。

public abstract class XNumber<T extends XNumber<T>> implements java.io.Serializable,Comparable<T>{
    private static final long serialVersionUID = 1L;
}

public final class XLong extends XNumber<XLong>  {
    private static final long serialVersionUID = 1L;

    @Override
    public int compareTo(XLong o) {
        return 0;
    }
}
分享到:
评论
6 楼 whitesock 2011-02-19  
public final class Float extends Number implements Comparable<Float> {
    public static final float NaN = 0.0f / 0.0f;
    ...
}

final Float nan1 = new Float(Float.NaN);
final Float nan2 = new Float(Float.NaN);
System.out.println(nan1.equals(nan2)); // ture
System.out.println(nan1.compareTo(nan2)); // 0
System.out.println(Float.NaN == Float.NaN); // false
5 楼 trydofor 2011-02-18  
fujohnwang 写道
float and double don't seem comparable

but they are
4 楼 fujohnwang 2011-02-18  
float and double don't seem comparable
3 楼 trydofor 2011-02-18  
http://stackoverflow.com/questions/480632/why-doesnt-java-lang-number-implement-comparable
2 楼 trydofor 2011-02-18  
NOT Comparable Number in JDK
AtomicInteger
AtomicLong

1 楼 trydofor 2011-02-18  
http://zh-cn.w3support.net/index.php?db=so&id=480632

相关推荐

    Multi-digit Number Recognition from Street View Imagery using DCNN

    Recognizing arbitrary multi-character text in unconstrained natural ...operating thresholds, the performance of the proposed system is comparable to, and in some cases exceeds, that of human operators.

    Rational Numbers

    – 由于有理数与整数、浮点数有许多共同特征,并且Number类是数字包装的根类,因此,把有理数类Rational定义为Number类的一个子类是比较合适的。由于有理数是可比较的,那么Rational类也应该实现Comparable接口。+下...

    java包装类相关方法.txt

    前面6个包装类是与数字相关的 父类:Number Boolean、Character 父类:Object 8个包装类实现的接口:Serializable ,Comparable 3、构造方法 前面6个包装类、Boolean 1、本身常量值的一个构造方法 ...

    java泛型总结.docx

    例如,List&lt;? extends Number&gt;表示一个可能是Number或其子类类型的列表。 类型推断:在Java 7及以上版本中,可以使用varargs和钻石操作符来推断类型参数。例如,List[] lists = Arrays.asList(new List() {{ add(...

    分数的加减乘除运算Rational Numbers

    – 由于有理数与整数、浮点数有许多共同特征,并且Number类是数字包装的根类,因此,把有理数类Rational定义为Number类的一个子类是比较合适的。由于有理数是可比较的,那么Rational类也应该实现Comparable接口。

    Global Optimization Schaeffler 2012

    Global optimization plays an outstanding role in applied mathematics, because a huge number of problems arising in natural sciences, engineering, and economics can be formulated as global optimization...

    Java 基础泛型.pdf

    例如,&lt;? extends Number&gt;表示只能使用Number及其子类类型。 4. 泛型类和泛型接口:在类或接口的定义中使用类型参数,从而实现类或接口的通用性。例如,List就是一个泛型类,Comparable就是一个

    A novel DDS using nonlinear ROM addressing with improved compression ratio and quantization noise

    The nonlinear addressing scheme is used to adaptively vary the number of interpolation points as the slope of the sinusoid changes, leading to a greatly reduced ROM size. The proposed architecture ...

    Reversible Recurrent Neural Networks.pdf

    scheme for storing a small number of bits in order to allow perfect reversal with forgetting. Our method achieves comparable performance to traditional models while reducing the activation memory ...

    JDK 1.5的泛型實現(Generics in JDK 1.5)

    值轉為外覆物件,或將外覆物件轉為數值。有了這項特性,我們可以將圖 3改寫 為圖 4,那就方便多了。 LinkedList&lt;Integer&gt; iList = new LinkedList(); iList.add(new Integer(0)); iList.add(new Integer(1));...

    javawiki源码-java_source_cn:Java1.8源码学习,详情见Wiki

    java wiki源码 ...Java1.8.0_91源码学习 Java源码学习1:java.lang.Void类 ...考虑到所有Number类的派生类都实现了Comparable接口,故而优先学习Comparable接口。 Comparable接口和Comparator接口是相似接口,需要对比下。

    occlusion reasoning for multiple object tracking

    abstract:Occlusion reasoning for visual object tracking in uncontrolled environments is a...experiments demonstrate that our approaches achieve results comparable to those of stateof- the-art approaches.

    Error analysis

    The number of multiplications required for matrix multiplication, for the triangular decomposition of a matrix with partial pivoting, and for the Cholesky decomposition of a positive definite ...

    Learning to rank for blind image quality

    number of images to train a robust model. However, the acquisition of image quality scores has several limitations: 1) scores are not precise, because subjects are usually uncertain about which score ...

    达内 coreJava 习题答案

    // i j k 分别为number 的百位、十位、个位 for (int sum; number; number++){ i=number/100; j=(number-i*100)/10; k=number-i*100-j*10; sum=i*i*i+j*j*j+k*k*k; if (sum==number) System.out.println(number...

    ruby语法基础教程

    §4.3 Number 34 §4.4 String 35 §4.5 Range 36 §4.6 Symbol 37 §4.7 正则表达式 37 第五章 代码块和迭代器 38 §5.1 代码块(Block) 38 §5.1.1 什么是代码块 38 §5.1.2 代码块与对象 39 §5.2 迭代器(Iterator...

    java常用工具类的使用

    Q 老师,时间毫秒值从1970年1月1日0:00.000开始计算,上面示例中10年后应该是1980年1月1日0:00.000,为什么输出结果是:1980年1月1日 8:00呢? A java.util.Date类型表示的是GMT时间,本身输出是国际化输出,...

    win3.x 下的wing 玩某些老游戏必备比如孔明传

    wing 你懂的不懂也不会下了。 Microsoft WinG version 1.0 -------------------------- This file describes known bugs, gotchas, and helpful hints for the WinG Version 1.0 final release. ISVs may want to ...

    雷达技术知识

    关于雷达方面的知识! EFFECTIVENESS OF EXTRACTING WATER SURFACE SLOPES FROM LIDAR DATA WITHIN THE ACTIVE CHANNEL: SANDY RIVER, OREGON, USA by JOHN THOMAS ENGLISH A THESIS Presented to the Department ...

Global site tag (gtag.js) - Google Analytics