lundi 20 avril 2015

Data type primitive object not initializing boolean correctly

Vote count: 0

I have to create a wrapper class to hold any primitive data type. I created the class, and it works as intended for everything except the boolean. This is my code:

byte a;
short b;
int c, j;
long d;
float e;
double f;
boolean g;
char h;
...;
public Primitive(boolean i) {
    g = i; 
    j = 6;
}

the top method works as intended, however, when I try my copy method, it makes the boolean value equal to true, regardless of whether i is true or false.

public Primitive(Primitive i){
    switch (i.j){
    case 0: a = i.a; break;
    case 1: b = i.b; break;
    case 2: c = i.c; break;
    case 3: d = i.d; break;
    case 4: e = i.e; break;
    case 5: f = i.f; break;
    case 6: g = i.g; break;
    case 7: h = i.h; break;
    }
}

Any help would be greatly appreciated.

asked 1 min ago



Data type primitive object not initializing boolean correctly

Aucun commentaire:

Enregistrer un commentaire