2

新的 Java shell,jshell,允许 tab 补全,它显示了类的给定实例可用的所有方法。例如,如果我这样做...

jshell> Integer myInt = 3
myInt ==> 3

jshell> myInt. <<< + TAB >>>
byteValue()     compareTo(      doubleValue()   equals(         floatValue()   
getClass()      hashCode()      intValue()      longValue()     notify()       
notifyAll()     shortValue()    toString()      wait(

...我看到了Integer对象可用的所有方法。如何查看整个类可用的方法和变量,而不仅仅是类的实例?

4

1 回答 1

2

实例Integer只会显示实例变量和方法 [ Oracle ]

jshell> Integer j = new Integer(3)
j ==> 3

jshell> j.
byteValue()     compareTo(      doubleValue()   equals(         floatValue()   
getClass()      hashCode()      intValue()      longValue()     notify()       
notifyAll()     shortValue()    toString()      wait(

...虽然可以通过简单地避免创建实例来查看非实例方法和变量:

jshell> Integer.
BYTES                    MAX_VALUE                MIN_VALUE                SIZE
TYPE                     bitCount(                class                    compare(
compareUnsigned(         decode(                  divideUnsigned(          getInteger(
hashCode(                highestOneBit(           lowestOneBit(            max(
min(                     numberOfLeadingZeros(    numberOfTrailingZeros(   parseInt(
parseUnsignedInt(        remainderUnsigned(       reverse(                 reverseBytes(
rotateLeft(              rotateRight(             signum(                  sum(
toBinaryString(          toHexString(             toOctalString(           toString(
toUnsignedLong(          toUnsignedString(        valueOf(
于 2018-01-15T20:37:29.053 回答