vrwim
vrwim

Reputation: 14300

Parameterized class without parameters?

In an Android framework I am trying to understand, I find a statement like this:

public Call<GeneralResponseSO> performApiCall(/*...*/) {
    // ...
}

But GeneralResponseSO is defined like this:

public class GeneralResponseSO<T> {
    // ...
}

Shouldn't the api method specify which type T is? I can't seem to grasp why the compiler doesn't give an error, and what type T then is.

Or does the compiler do magic to filter out all the generics from the class? So that all variables/methods that use T are removed? I wouldn't expect the Java compiler to perform such magic though.

Upvotes: 0

Views: 525

Answers (1)

Mạnh Quyết Nguyễn
Mạnh Quyết Nguyễn

Reputation: 18235

A generic class / interface without type parameter is Raw type.

Raw type is unchecked during compile (and you may see warning in IDE such as Intellij) and may cause exception at runtime.

Note: Example.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

You can read more here

Upvotes: 2

Related Questions