user1725145
user1725145

Reputation: 4042

What is the Java VM type signature for a method returning a generic class type?

The method is

public Set<BluetoothDevice> getBondedDevices ()

from Android.bluetooth.BluetoothAdapter.

I read the type signature guidance here, including how to specify an object with Lclass-name; but I don't know how to extend that to a generic class (or even if it is possible).

Upvotes: 0

Views: 155

Answers (3)

Oo.oO
Oo.oO

Reputation: 13405

If you are not sure what is the signature of the method, javap comes to rescue.

import java.util.*;
public class Example {
  public Set<Float> getSet() {
    return null;
  }
}

you can easily check the signature following way

> javac Example.java
> javap -s -cp . Example
Compiled from "Example.java"
public class Example {
  public Example();
    descriptor: ()V

  public java.util.Set<java.lang.Float> getSet();
    descriptor: ()Ljava/util/Set;
}

Upvotes: 1

Perimosh
Perimosh

Reputation: 2824

You are asking about Type Erasure in java. Your answer is Object. If you have:

List<E> myList;

The compiler will interpret E as Object. This case is known as Class Type Erasure. There is also a case called Method Type Erasure.

Upvotes: 0

SLaks
SLaks

Reputation: 887867

Generics do not exist at runtime; AFAIK, that syntax does not support type parameters.

I'm not sure if that applies to type parameters for base classes (which do exist at runtime in Reflection).

Upvotes: 1

Related Questions