Hi All,

This is a sample function for making an object from string at run
time. Here we are not casting the object but creating one. I wanted
the same thing for casting the object.

public static Object bindObject(Class className) {
        Object objOutput = null;
        try {
            String sClassName = className.getPackage().getName().concat
(".Wrap".concat(className.getSimpleName()));
            objOutput = Class.forName(sClassName.replaceFirst
("com.vtech", "com.vtech.appxtension")).newInstance();
        } catch (Exception e) {
            try {
                objOutput = Class.forName(className.getName
()).newInstance();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

        return objOutput;
    }


Thanks to all for kind support..
Amit Kumar Verma

On Apr 18, 8:51 pm, Timothy Perrett <timo...@getintheloop.eu> wrote:
> So your talking about reflection right? Take a look at scala Manifests
> (which aide getting round type erasure) - other than that scala supports all
> the normal reflection tooling that Java does.
>
> Tim
>
> On 18/04/2009 06:56, "Amit Kumar Verma" <cdac.a...@gmail.com> wrote:
>
> > "Scala is a static language, so the class for casting must be known at
> > compile time.  It's not possible to construct a String at runtime and
> > cast
> > an object into a class represented by that String. "
>
> > But we use this feature in Java for casting the objects.

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

Reply via email to