Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I generate foo_= and foo accessors from setFoo and getFoo?

Tags:

scala

I'm getting started with using Scala on Android and a lot of the accessor methods are standard JavaBeans accessors, e.g. setTitle(...) and getTitle(). It's a lot nicer to use the title_= and title methods in scala, so I can write code like:

button.title = "Foo"

Is there any way to automatically map these from JavaBeans-style accessors, maybe using the Dynamic trait?

like image 626
Bill Avatar asked Jun 05 '11 15:06

Bill


Video Answer


1 Answers

I think Dynamic would work, except it is not presently supported with syntactic sugar. Also, it would return AnyRef since there's no way to pass what the expected return type is.

Of course, you can simply use pimp my library to add appropriate Scala-style getters and setters.

like image 158
Daniel C. Sobral Avatar answered Sep 19 '22 00:09

Daniel C. Sobral