Re: [android-developers] Java Generics question (Using AsyncTask)...

2011-06-15 Thread luciofm
Thanks for the response...

I've just saw it today...

this is my class declaration public class AsyncRequestT extends
AsyncTaskObject, Void, AsyncResponseT {

using getTypeParameters
TypeVariable?[] types = getClass().getTypeParameters();

types[0].getBounds()[0] is a class java.lang.Object

The only way I got it working is when instantiating my class
AsyncRequestResponseDTO asyncRequest = new
AsyncRequestResponseDTO(mContext, asyncResponseListener){};

Using an empty anonymous inner class

Lúcio Maciel
luci...@gmail.com



On Fri, Jun 10, 2011 at 03:13, Nikolay Elenkov
nikolay.elen...@gmail.com wrote:
 On Thu, Jun 9, 2011 at 9:31 AM, luciofm luci...@gmail.com wrote:

 In this case, with getSuperclassTypeParameter() I get the parameterized
 types of AsyncTask, and not of my own Class AsyncRequest...
 (parameterized.getActualTypeArguments()[0] is a String type).


 That's the way  getGenericSuperclass() is supposed to work. Use
 getTypeParameters() to get the generic variables of the current class.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Java Generics question (Using AsyncTask)...

2011-06-10 Thread Nikolay Elenkov
On Thu, Jun 9, 2011 at 9:31 AM, luciofm luci...@gmail.com wrote:

 In this case, with getSuperclassTypeParameter() I get the parameterized
 types of AsyncTask, and not of my own Class AsyncRequest...
 (parameterized.getActualTypeArguments()[0] is a String type).


That's the way  getGenericSuperclass() is supposed to work. Use
getTypeParameters() to get the generic variables of the current class.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Java Generics question (Using AsyncTask)...

2011-06-09 Thread luciofm
Hi,

I'm having some troubles with generics, trying to get the Type of my
Parameterized class???

Let's begin with a working example...

class TestClassT {
Type type;

public TestClass() {
type = getSuperclassTypeParameter(getClass());
}

static Type getSuperclassTypeParameter(Class? subclass) {
Type superclass = subclass.getGenericSuperclass();
if (superclass instanceof Class) {
throw new RuntimeException(Missing type parameter.);
}
ParameterizedType parameterized = (ParameterizedType) superclass;
return parameterized.getActualTypeArguments()[0];
  }
}

Whit this code, I can get at runtime, the Type of T (like TestClassString
will return a String type).

My problem is when I have a generic class extending another generic class.

class AsyncRequestT extends AsynTaskString, Void, AsyncResponseT {
Type type;
public AsyncRequest() {
type = getSuperclassTypeParameter(getClass());
}

static Type getSuperclassTypeParameter(Class? subclass);
}

In this case, with getSuperclassTypeParameter() I get the parameterized
types of AsyncTask, and not of my own Class AsyncRequest...
(parameterized.getActualTypeArguments()[0] is a String type).


Anyone has some ideia of how I can get the Type of T of my own Class???

Thanks in advance...
Lúcio Maciel
luci...@gmail.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en