What overloaded method is Groovy picking when null is passed as a parameter?

class SimpleTest {
    void met( Object a ) {
        println "Object"
    }

    void met( String b ) {
        println "String"
    }

    static main( args ) {
        SimpleTest i = new SimpleTest()
        i.met(null)
    }
}

This code will return the result "Object". He will not choose the most specialized version of the method. In this case, String is more specialized than Object, so this rule does not apply.

+5
source share
1 answer

Groovy . , , , ( ) ( ). , , 3, 1, 1, vargs ( ​​ , )

null , . . , . Java , . Groovy , , , . , . .

, . null, Object, .

, . : , , 1. - , , , , ", . . , . +1 ( ). , , .

null ... 1, . , +1. , .

List Integer null.
List extends Collection, Collection extend Iterable, Iterable . 1 Iterable, 2 Collection , , 3 List. , . , 6 (2x3), , . , , . , .

+8

All Articles