scala - Override field with parameterless method -


I am currently learning Scala and I am reading Martin Ordesky's book (from the cover). In Chapter 10 I found this:

Enter image details here < P> Excellent I understand both and in this way. So I tried an example:

  class father {def x = 1 // method} increases the child's dad in the class (overlays well x = 1; // field}   

However, if you try to override an attribute with a method:

  class father father {val x = 1; // field} class I get a compiler error:  
  The method x should be a static, irreversible value override (override def x = 1 // method)   

Def X = 1

This does not work if x is in dad var :

  Method x can not override a floating variable override def x = 1   

so we have two cases (and I have two questions): < Ul>

  • Trying to override an unqualified field: In this order of guarantee, x will not be overridden by a method whose value varies more Until the time? Is there any other reason?
  • A The variable region is trying to override: Why can not override an unqualified area? I initially thought that this is to avoid class users assigning values ​​to parameters without parameters, but then no parameter-based method should be allowed.

    a val to def

    A var should be allowed to override at def what will it mean?

  • Comments

    Popular posts from this blog

    php - PDO bindParam() fatal error -

    logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

    java - Why my included JSP file won't get processed correctly? -