Inspection '==' instead of 'equals', private constructors, and interfaces
The inspection has an option to ignore '==' between objects of a
type with only private constructors. Yet, that does not apply to
interfaces, so it clashes with best practices and a couple of other
inspections, that advise to use interfaces instead of concrete classes.
So, if instances referenced via an interface are compared with '==':
Is it feasible to check if all implementors of that interface have private
constructors, only? Or would the performance be too bad?
This would save me a lot of inspection warnings...
Please sign in to leave a comment.
Stephen Kelvin wrote:
A reasonable suggestion. I'm not sure about the performance, but I
imagine that in the case of many implementors this could cause quite a
significant slowdown. Perhaps I could make it another option if it turns
out to be slow and document the slowdown there. Could you submit a JIRA
request about it?
Bas
Thanks!
http://www.jetbrains.net/jira/browse/IDEA-6091
"Bas Leijdekkers" <leijdekkers@SPAMBLOCK.carp-technologies.nl> wrote in
message news:4399785B.3080505@SPAMBLOCK.carp-technologies.nl...
>> The inspection has an option to ignore '==' between objects of a
>> type with only private constructors. Yet, that does not apply to
>> interfaces, so it clashes with best practices and a couple of other
>> inspections, that advise to use interfaces instead of concrete classes.
>>
>> So, if instances referenced via an interface are compared with '==':
>> Is it feasible to check if all implementors of that interface have
>> private
>> constructors, only? Or would the performance be too bad?
>> This would save me a lot of inspection warnings...
>
>
You could process only a limited number if inheritors to prevent slowdown,
otherwise the contract to have only private constructors is anyway too
fragile and is going to be broken someday.
Eugene.
Eugene Vigdorchik (JetBrains) wrote:
>> Stephen Kelvin wrote:
>>> The inspection has an option to ignore '==' between objects of a
>>> type with only private constructors. Yet, that does not apply to
>>> interfaces, so it clashes with best practices and a couple of other
>>> inspections, that advise to use interfaces instead of concrete classes.
>>>
>>> So, if instances referenced via an interface are compared with '==':
>>> Is it feasible to check if all implementors of that interface have
>>> private
>>> constructors, only? Or would the performance be too bad?
>>> This would save me a lot of inspection warnings...
>>
>> A reasonable suggestion. I'm not sure about the performance, but I imagine
>> that in the case of many implementors this could cause quite a significant
>> slowdown. Perhaps I could make it another option if it turns out to be
>> slow and document the slowdown there. Could you submit a JIRA request
>> about it?
>>
>> Bas
Excellent, I will do that. How many inheritors shall I limit it too
(what's the usual limit in IDEA)?
Bas
>
I recall we have 5 for showing tooltip for "Inherited in" in the gutter.
Sounds reasonable here as well, what do you think?
Eugene.