JAVA - cast using class obtained by its name (string value)

I think what you are trying to do can be achieved with generics.

For example a method like this:

     public <E> List<E> getList(Class<E> clazz) {
         List<E> result = new ArrayList<E>();
         if(clazz != null){
             Query query = mgr.newQuery(MyClass.class);
             for(E obj : (List<E>)query.execute()) {
                 result.add(obj); 
             }
         }

         return result;
     }

Can be called with:

 getList(TheChosenOne.class)

And it will return a List<TheChosenOne> object


What you are trying to do is unnecessary because your list is declared as List<Object> so the cast is not needed.

-- Before Edit --

Not sure I understand what you need, but did you try to use:

Class.cast(object)

This is a method of the java.lang.Class