关于Boolean对象的compareTo方法的一些疑惑 booleanjdkjava 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 按源码也等于0啊public static int compare(boolean paramBoolean1, boolean paramBoolean2) { return paramBoolean1 ? 1 : paramBoolean1 == paramBoolean2 ? 0 : -1; }假设paramBoolean1=TRUE,paramBoolean2=TRUEparamBoolean1 ? 1 : paramBoolean1这个表达式的结果是11 == paramBoolean2 ? 0 : -1;这个表达式的结果是0没有问题啊 true>false false<truetrue==true false==false都是true,自然相等,没有小于对方,也没有大于对方,返回0. 引用 楼主 u010444251 的回复:话不多说直接进主题 jdk1.7 eclipse luna 关于compareTo方法的api文档解释是: 如果对象与参数表示的布尔值相同,则返回零;如果此对象表示 true,参数表示 false,则返回一个正值;如果此对象表示 false,参数表示 true,则返回一个负值 java代码 System.out.println("new 楼主不厚道啊!Boolean.java的源码:/** * Compares this {@code Boolean} instance with another. * * @param b the {@code Boolean} instance to be compared * @return zero if this object represents the same boolean value as the * argument; a positive value if this object represents true * and the argument represents false; and a negative value if * this object represents false and the argument represents true * @throws NullPointerException if the argument is {@code null} * @see Comparable * @since 1.5 */ public int compareTo(Boolean b) { return compare(this.value, b.value); } /** * Compares two {@code boolean} values. * The value returned is identical to what would be returned by: * <pre> * Boolean.valueOf(x).compareTo(Boolean.valueOf(y)) * </pre> * * @param x the first {@code boolean} to compare * @param y the second {@code boolean} to compare * @return the value {@code 0} if {@code x == y}; * a value less than {@code 0} if {@code !x && y}; and * a value greater than {@code 0} if {@code x && !y} * @since 1.7 */ public static int compare(boolean x, boolean y) { return (x == y) ? 0 : (x ? 1 : -1); }不知道你的这个源码从哪里看的 擦,我是用反编译工具直接反编译rt.jar包的 看来这工具还是不值得相信啊 String .getBytes() 指点一下 在jsp页面中,讲鼠标变成小手 关于Java中的输入问题…… 读写Xml文件乱码问题 Image img=kit.getImage("")麻烦大家看看! 怎么我图形界面中的按钮显示不了中文? 简单问题(在线等待) 各位有经验的高手,我想问一下java可开发的东东多不多?java前途如何〉? Maven Assembly Descriptor的outputDirectory标签能够使用的属性 赋值问题 java成员初始化时调用的语句需要抛出异常,该怎么处理
public static int compare(boolean paramBoolean1, boolean paramBoolean2)
{
return paramBoolean1 ? 1 : paramBoolean1 == paramBoolean2 ? 0 : -1;
}
假设paramBoolean1=TRUE,paramBoolean2=TRUE
paramBoolean1 ? 1 : paramBoolean1这个表达式的结果是1
1 == paramBoolean2 ? 0 : -1;这个表达式的结果是0没有问题啊
true==true false==false
都是true,自然相等,没有小于对方,也没有大于对方,返回0.