Which constructor is chosen when passing null?

前端 未结 3 1976
醉话见心
醉话见心 2021-01-17 23:24

In the following example, I have 2 constructors: one that takes a String and one that takes a custom object. On this custom object a method \"getId()\" exists which returns

3条回答
  •  一整个雨季
    2021-01-18 00:03

    Java uses the most specific contructor it can find according to arguments.
    PS: if you add constructor (InputStream) , compiler will throw error because of ambiguety - it cannot know what is more specific: String or InputStream, because they are in different class hierarchy.

提交回复
热议问题