I have got a constructor which takes 4 parameters: String, Object, Object, MyEnum
.
public MyClass(String name, Object val1, Object val2, MyEnum cat) {
// find in usage = 202
this.name = name;
this.val1 = val1;
this.val2 = val2;
this.cat = cat;
}
In 95% usage cases last parameter is null
, so I would like to create another constructor which takes only 3 parameters and sets last one as a null.
Some ideas came to my mind but finally I gave a try to the following solution:
Change last parameter from
MyEnum
toInteger
(compilation error - does not matter):public MyClass(String name, Object val1, Object val2, Integer cat)
- still 202 find usageAdd new constructor with last parameter of type Object:
public MyClass(String name, Object val1, Object val2, Object cat)
and now first constructor (withInteger
) has 196 usages and second one 6.
This is exactly what I wanted (I have got exactly 6 invocations with non null last element) but what is the reason of this behaviour? Does Intellij make some checks and if input type is MyEnum
it cannot be passed as an Integer
type, but null can be passed to both, so why in case of first constructor there is 6 less results?
When I changed from Object
to String
(now I have 2 constructors with String
and Integer
) both give me 0 when I run find usage.
Thank you for the explanation of this behaviour.