inheritance - Scala abstract method is null in superclass when subclass implements it using val? -


I got an error in my scale code, which makes me puzzle below is a simplified version of the problem.

In the constellation of an abstract class, I want to know something about abstract methods in some ways. Thus, when a subclass is created, they are checked, to see if everyone should apply it.

It goes wrong when the subclass implements an abstract method using a "wall":

Scala code:

  Abstract class A {def aval: string thrust (aval! = Null, "aval == null") emphasis (aval == "B", "Aval:" + aval)} extension of class B A {def aval = "B" VariousScalaTests object {args: Array [String]): unit = {val slash error:  
  Exceptions in thread "main" class = A {val aval = "B"} Java.lang.AssertionError: Claim Fail: Aval == Scale on tap. Pedfeh $. Asset (Preface: Scala: 92) AT & Lt; Init & gt; (Miscellaneous titles. Scala: 4) c. And lieutenant; Init & gt; (Miscellaneous titles.Syaka: 19) on various scallat's men (various scalestasts)  

so it fails the last line of code: "val c = new c "Class B works perfectly, but class is not C! The only difference is that using" val "and" b "is used using" av "and" def ".

So my question, most, why is this difference? I do not understand Yes, that's what is happening.

And is it a way to do this, as I want in Scala, in both cases? Or to claim what I want in Scar I am missing in another great way?

This equivalent java code should be understood by this problem:

/ P>
  Public abstract class A {public string aval ();} Extended public { C Aval () {return "B";}} public class C a {private String _aval; public C () {_aval = "B";} public string Aval () {return _vl; }}  

When you are the creator of A

  val c = new c  

/ code > The manufacturer and the _aval field of Run ago c has not been assigned yet. Therefore aval () method returns null (the initial values ​​of the _aval field).

Generally

And is this a way to do this because I want to do both cases in Scala?

Look for some methods.


Comments

Popular posts from this blog

paypal - How to know the URL referrer in PHP? -

oauth - Facebook OAuth2 Logout does not remove fb_ cookie -

wpf - Line breaks and indenting for the XAML of a saved FlowDocument? -