2

I have a Java class like:

public class User {
   public String name;
   public String email;
}

Instead of creating another case class in Scala or using tuple, can I do something like

Form<User> form = Form.form(User.class)

The above code is possible in Play Java but not for Scala

Dennis Kriechel
  • 3,719
  • 14
  • 40
  • 62
NSF
  • 2,499
  • 6
  • 31
  • 55
  • Just an idea, but should work: What happens if you just import the Java form class and use it (i.e. use `play.data.Form` instead of the default one for Scala, `play.api.data.Form`)? You should be able to use that one from Scala exactly like from Java. Well, almost exactly, more like `form:Form[User] = Form.form(User.class)` – Carsten Aug 05 '13 at 18:52
  • @Carsten I tried but Scala didn't allow me to use .class – NSF Aug 05 '13 at 19:18
  • http://stackoverflow.com/questions/1135248/scala-equivalent-of-java-java-lang-classt-object – Carsten Aug 05 '13 at 19:50

1 Answers1

2

.class isn't a keyword in Scala. Try classOf[User].

i.e.

val form = Form.form(classOf[User])
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180