Deprecate self
D-Man
dsh8290 at rit.edu
Wed Apr 18 12:00:47 EDT 2001
On Wed, Apr 18, 2001 at 05:10:43PM +0200, Steve Purcell wrote:
| Rainer Deyke wrote:
| > My C++ code has become much more readable since I started referring to
| > member variables through 'this'.
|
| I had the same experience with Java. Writing 'this' also helps to avoid
| having to artificially mutate variable names that are logically related
| in code such as:
...
| Now, I've admittedly been corrupted by Python,
Same here.
It doesn't work quite as nicely with inner classes though :
public class Bar extends JFrame
{
public Bar()
{
JButton b = new JButton( "Hello" ) ;
b.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
this.doSomething() ;
}
} ) ;
this.getContentPane().add( b ) ;
}
public void doSomething()
{
System.out.println( "Button pressed" ) ;
}
}
$ jikes -classpath d:/jdk1.2.2/lib/rt.jar Bar.java
Found 1 semantic error compiling "D:/apps/cygwin/home/derrick/tmp/random_checks/
Bar.java":
15. this.doSomething() ;
<---------------->
*** Error: No method named "doSomething" was found in type "Bar$1".
OTOH inner classes are used so heavily because functions aren't
objects and thus can't be used as callbacks/event handlers
-D
More information about the Python-list
mailing list