1

I am writing a generic class and used the following code:

public class MyClass<P>{

}

I am getting a warning "The type parameter P is hiding the type P" . what does that mean?

Stultuske
  • 9,296
  • 1
  • 25
  • 37
Sonia Jain
  • 143
  • 2
  • 10
  • 6
    It seems that somewhere there is a class named P, which you are 'hiding' – Stultuske Jan 30 '18 at 07:23
  • 1
    @Stultuske or there is a type variable called P in the containing class (P is not necessarily a class). – Andy Turner Jan 30 '18 at 07:27
  • @AndyTurner the moment it says hiding 'the type' P, my first guess is not a variable, but a class. – Stultuske Jan 30 '18 at 07:32
  • either way, it is a 'Type' declared somewhere, whether it is a passed generic or a class/interface, but I expect there's more code to check than just this. – Stultuske Jan 30 '18 at 07:39

1 Answers1

1

There should be a class (or inner class or outer type parameter (thanks Andy)) inaptly named P on your classpath. To find it, first change to this:

public class MyClass {
    P p;
}

Then Ctrl-click P in your IDE (or whatever shortcut takes you to the declaration of an identifier). If that doesn't work, try auto-import to see which import appears at the top.

Mark Jeronimus
  • 9,278
  • 3
  • 37
  • 50