Start New Discussion within our Software Development Community

Hello DaniWeb. Just brushing up on some Java and got a quick syntax question. What does the this code do?

LoginForm formBean = (LoginForm)form;

Now I know that a formBean object of type LoginForm is being created but I dont know what its being declared with. Whats happening on the other side of the equation? I'm assuming that this is another way of creating a form object of LoginForm type but I need to know for sure.

Check:

System.out.println(form.getClass());

Tray:

public static void main(String args[]) {
        List list = new ArrayList();
        list.add(new Point(3, 4));
        System.out.println(list.getClass());
        Object ob = list;

        System.out.println(ob.getClass());
        ArrayList al = (ArrayList) ob;
        System.out.println(al.getClass());
        List list2 = (List) ob;
        System.out.println(list2.getClass());
        AbstractList abstl = (AbstractList) ob;
        System.out.println(abstl.getClass());
        AbstractCollection ac = (AbstractCollection) ob;
        System.out.println(ac.getClass());
        Object[] objArr = abstl.toArray();
        System.out.println(objArr[0].getClass());
        //
        ArrayList al3 = (ArrayList) abstl;
        System.out.println(ac.getClass());
        Collection coll = (Collection) list;
        System.out.println(coll.getClass());

Casting to classes (in the chain of inheritance) , interfaces. But list is always ArrayList.
Created is new varible "formBean", that refer to (represent) the same object "form".
http://java.sun.com/docs/books/tutorial/java/IandI/subclasses.html

This article has been dead for over six months. Start a new discussion instead.