Code Completion shows subclass methods

Answered

When I have a variable of base class/interface type which references a subclass object, I expect code completion on the variable to show only methods visible to the base type. See the snapshot below. In this example, code complete on variable of type Queue is showing methods of LinkedList too.

Is there a way tune the behavior? Or is it a bug?

 

0
1 comment
Official comment

This is a feature, not bug. Some users like it, as often you declare variable with more abstract type, then want to make it more specific to access more methods, especially together with "Too weak variable type leads to unnecessary cast":

 

Currently there's no way to switch this behavior off. Probably the problem could be mitigated were items which require casts visually different from other items. There's a ticket for this: IDEA-194568. Another possibility would be to display such items only when completion hotkey like Ctrl+Space is pressed explicitly. I filed IDEA-199341. You may vote for these tickets.

Please sign in to leave a comment.