Tuesday 15 February 2011

Self-titled field and accessor in Scala -


It has been learned that name slab allows for object-personal variables and methods such as the following: class test {private [this] var x = 1 def x (): string = this.x.toString}

This code is at least Scala 2.10 Is valid and produces what I expect (unrelated to Java):

  public class exam {Private int x; Public string x () {return BoxesRunTime.boxToInteger (x) .toString (); } Public examination () {x = 1; The problem is that I am not sure that I can count on this behavior later in Scala releases because I could not find any official evidence in the specifications of this behavior. . by design. So, can anyone tell me a source of such knowledge?  

Update: My goal is to use this approach to map the Hibernate data model with scala classes. Since there is no easy way to support the Hibernate Scala compilation, I want to map a Java archive to a private area, which is then wrapped in a self-titled accessor method in a slab archive. The important requirement is to keep the method and the method with the same name because I also want to preserve the logical Hibernate compilation name, e.g. To referencing it in HQL

These collisions are completely normal, but keep in mind that reading your code can be a problem because These should show the collisions (if you need it) in other cases only for gates / sets, please use clear method names such as:

  def xAsString ():   

This thread may also be useful

and this

No comments:

Post a Comment