Bug or somebody has an explanation?

Well, seems JavaFX processor (it is not yet a compiler I guess) behaves strangely.
I have simple ClassChild inheriting from ClassParent:

ClassParent.fx
package strangeinheritance;

class ClassParent {
    attribute a: Number;
    attribute b: String;
}
ClassChild.fx
package strangeinheritance;

class ClassChild extends ClassParent {
    attribute b: Integer;
    attribute c: String;
}

attribute ClassChild.b = 100;
attribute ClassChild.c = "any text";

and simple usage scenario:

Main.fx
package strangeinheritance;

import java.lang.System;
var cc = ClassChild{};
var cp = ClassParent{};
System.out.println("cc.a = {cc.a}, cc.a.class = {cc.a.class}");
System.out.println("cc.b = {cc.b}, cc.b.class = {cc.b.class}");
System.out.println("cp.b = {cp.b}, cp.b.class = {cp.b.class}");
System.out.println("cp.a = {cp.a}, cp.a.class = {cp.a.class}");

I really surprised that this code runs, but it does:

cc.a = 0, cc.a.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0
cc.b = 100, cc.b.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0
cp.b = 0, cp.b.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0
cp.a = 0, cp.a.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0

Looks as if interpreter knows nothing about b:String declaration in ClassParent🙂
What I found and what surprised me much, I added only 2 lines to Main.fx:

package strangeinheritance;

import java.lang.System;
import strangeinheritance.ClassChild;
import strangeinheritance.ClassParent;
var cc = ClassChild{};
var cp = ClassParent{};
System.out.println("cc.a = {cc.a}, cc.a.class = {cc.a.class}");
System.out.println("cc.b = {cc.b}, cc.b.class = {cc.b.class}");
System.out.println("cp.b = {cp.b}, cp.b.class = {cp.b.class}");
System.out.println("cp.a = {cp.a}, cp.a.class = {cp.a.class}");

And I got (as one should expect):

Error in file:/home/alex/NetBeansProjects/StrangeInheritance/src/strangeinheritance/ClassChild.fx:8: incompatible types: expected String, found Integer in 100

This behaviour looks correct. Any idea why? or just a bug?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: