Search code examples
javatab-completionjshell

jshell tab completion non-instance methods


The new Java shell, jshell, allows tab completion which shows all methods available to a given instance of a class. For example, If I do...

jshell> Integer myInt = 3
myInt ==> 3

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

...I see all of the methods available to an Integer object. How do I see the methods and variables available to the class at large, not just an instance of the class?


Solution

  • An instance of Integer will only show the instance variables and methods [ 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(
    

    ...while non-instance methods and variables can be seen by simply refraining from creating an instance:

    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(