• kvp
    #36
    "JAVA int példa nagyon rossz."

    Nem a szintaxisrol van szo, hanem arrol, hogy a java belul (a runtime motorban) mashogy kezeli az int-eket es az Integer-eket. Az egyik nativ tipuskent van kezelve, a masik objektumkent. A nativ tipusok lete eleve egy kivetel, mivel tiszta oop nyelven nincs ilyen. Tehat a 2.toString()-nek is mukodnie kellene. Java eseten a nagyobb sebesseg miatt ezt a tudast kisporoltak. Ezert lehet java-ban nagyon egyszeruen proceduralis kodot irni. Az android forrasa tele van jo peldakkal.

    A javascript-es kod nagyjabol trivialis: (adatrejtes es statikus valtozok nincsennek, a javascript egy teljesen dinamikus oo nyelv)

    var nextId = 1;

    var Parent = function(){ this.id = nextId++; };
    Parent.prototype.calc = function(v){ return(v*2); };
    Parent.prototype.getVal = function(){ return(this.calc(this.id)); };

    var Child = function(){};
    Child.prototype = new Parent();
    Child.prototype.calc = function(v){ return(Parent.prototype.calc(this.id)+1); };

    var c = new Child();
    var p = new Parent();

    document.write('Child='+c.getVal());
    document.write('<br>');
    document.write('Parent='+p.getVal());

    Egyebkent meg szerintem a smalltalk-hoz kepest mindket pelda iszonyat ronda, bar mukodnek...