It's easy to replace use of class.forName with a hash map containing the 
finite list of classes you need to instantiate,
but one word of caution, if your list is extensive, conceal the list from 
the low level utility that replaces it, otherwise
all the headers for all the classes in the list become part of every 
class.   In my rather extreme case, doing so
resulted in a 50% reduction in IOS build time.

    static public Hashtable<String, Class<?>> namedClasses = new 
Hashtable<String,Class<?>>();

    public static Class<?> classForName(String name,boolean testOnly) 
    {    Class<?>cl = namedClasses.get(name);
...}

On Friday, May 27, 2016 at 9:24:26 PM UTC-7, Shai Almog wrote:
>
> Hi,
> so the way we do an abstraction of implementation is thru class literals. 
> E.g. see the native interface support: 
> https://www.codenameone.com/manual/advanced-topics.html#_native_interfaces
>
> This works by using code such as:
>
> MyNative my = NativeLookup.create(MyNative.class); 
> if(my != null && my.isSupported()) { 
>    Log.p(my.helloWorld("Hi")); 
> }
>
> Notice that "MyNative" is an interface not the implementation class and the 
> build server injects the glue code to 
> the native code. Once it has that glue code in place it just does a 
> put(class,impl) into the native lookup map 
> which we can then query for the real implementation.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/5f3950b2-a50e-4a20-8c97-af0d0593cf7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to