#220 Cast unsuccessful

open
nobody
None
5
2005-06-15
2005-06-15
Nigel
No

Atempting to work around problem 1221300 with the
following:

class t4 {
public String answer = "Yes";

public void w() {
String answer = "No!";
}
}
public class t4ext extends t4 {

public String answer = "No!";

public void w() {
String answer = "Maybe";
System.out.println("Is Nigel best?
> " + ((t4)this).answer);
}

public static void main(String[] args) {
t4 w = new t4ext();
w.w();
}
}

Process cat exited with code 0

Works in Java:
> javac t4ext.java
Process javac exited with code 0
> java t4ext
Is Nigel best? > Yes
Process java exited with code 0

BeanShell still hasn't read "How to make friends and
influence people":
/home/nigel/myBsh/Pitfalls/temp/> java -
classpath ../../bsh-2.0b4.jar bsh.Interpreter t4ext.java
Is Nigel best? > No!
Process java exited with code 0

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks