GithubHelp home page GithubHelp logo

Comments (3)

jeffdgr8 avatar jeffdgr8 commented on August 27, 2024

I found a workaround (documented in StackOverflow post), but this may pop up as a common issue for people with the constructor formatted the way it is. In my case, the object returned by my network service is a Map with various Objects (Strings, Integers, ArrayLists, etc.) from an XML-RPC call and so I need to use the generic class type Map<String, ? extends Object> for the result type in SpiceRequest.

from robospice.

stephanenicolas avatar stephanenicolas commented on August 27, 2024

Hi @jeffdgr8,

this problem is not really related to RoboSpice itself but to a limitation of the Java syntax : there is no litteral that you can use to get the class/type of a parametrized generic type in Java.

If you want to do something like

public class ListTweetRequest extends SpiceRequest<List<Tweet>> {

   public ListTweetRequest(Object cacheKey ) {
       super( <Here is the problem>, cacheKey );
   }
}

then you can't pass the class List<Tweet>.class to you parent constructor. That's really a Java limitation as generics are realized using type erasure and List<Tweet>.class has no real meaning in Java.

The best and cleanest work around is to use an intermediate type like :

public class ListTweet extends List<Tweet> {
}

public class ListTweetRequest extends SpiceRequest<ListTweet> {

   public ListTweetRequest(Object cacheKey ) {
       super( ListTweet.class, cacheKey );
   }
}

This has the advantage to provide you with a real type that you can pass to the SpiceRequest's constructor. But beware of obfuscation. In thoses cases, proguard will try to remove the ListTweet class, you have to explicitly preserve it from obfuscation.

from robospice.

jeffdgr8 avatar jeffdgr8 commented on August 27, 2024

OK, thank you for the info. That is helpful.

from robospice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.