Kazuya Tomita Kazuya Tomita - 1 year ago 75
Java Question

The difference between "new Form(A.class)" and "form(A.class)" in PlayFramework?

I am using PlayFramework 2.2.1 and I have a question about the difference between

new Form(A.class)

In PlayFramework you have to pick values from a specific form in Web page if you want to use these values in your application. And normally I am using the
instance and the
method like this:

Form<OneForm> f = new Form(OneFrom.class).bindFromRequest();

But I also see this code in a certain guiding book:

Form<OneForm> f = form(OneForm.class).bindFromRequest();

Is there any difference between them? If you have any idea, please teach me.

Answer Source

There's no difference. Both creates instances of a Form that wraps the OneForm.class (Check out the source):

public static <T> Form<T> form(Class<T> clazz) {
    return new Form<T>(clazz);

So its just a convenience/wrapper method. On another note the form(..) method is deprecated in later versions of play (specifically 2.5). So perhaps it's best you stick with the first version if you plan to upgrade the framework to the latest in the future.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download