| Author |
what is the problem with my java code
|
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
error is
|
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
|
 |
Alexander Kober
Ranch Hand
Joined: Aug 05, 2011
Posts: 32
|
|
As you can see in line 10, the constructor of class 'Playing' takes a String argument. The field Playing#name is of type Playing.Name, an enum you defined. Java will not automatically convert a String to the corresponding enum value. In line 40, you actually do pass an enum to the constructor, so i guess all you'll want to do is replace line 10 with
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Also, the setNames method seems wrong. First of all, it doesn't set anything, so it should be called getName instead. Second, it can be implemented so much easier:
And should you ever need to convert a String into one of your enum constants, you can use Name.valueOf("thriller").
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
Alexander Kober wrote:As you can see in line 10, the constructor of class 'Playing' takes a String argument. The field Playing#name is of type Playing.Name, an enum you defined. Java will not automatically convert a String to the corresponding enum value. In line 40, you actually do pass an enum to the constructor, so i guess all you'll want to do is replace line 10 with
thanks for guiding me . my doubt is clear now but i want to ask 1 question which is
when i change to this so after changing this i thought it should not produce an error but it did , i m passing an String value which is accepted by constructor Playing(String name) then it should set the name to the value of constructor then i m calling the which should set the appropriate name according to the value of name variable into names variable
the error is
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Well, you can't use Strings inside switch statements. (Well, since Java 7 you can, but you'd need to compare them to String values.)
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
Rob Spoor wrote:Well, you can't use Strings inside switch statements. (Well, since Java 7 you can, but you'd need to compare them to String values.)
thanks
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
You're welcome.
|
 |
 |
|
|
subject: what is the problem with my java code
|
|
|