[Bluej-discuss] requiring "this"

Stephen Bloch sbloch at adelphi.edu
Mon Nov 19 15:39:06 GMT 2007


Barry Brown writes:
>I think this is a great idea from a pedagogical standpoint. My BlueJ 
>students seem to understand variable and parameter names. When the 
>book introduces "this" in a constructor, it really throws the students 
>for a loop. Up until that point, they have this idea that Java names 
>are "global" and should be distinct within a class. Seeing a field and 
>a parameter with the same name really gives them trouble and they have 
>difficulty getting their heads around it.
>
>I'm going to try using the "this" technique this coming semester. 
>Problem is, the BlueJ book doesn't consistently use it. Can we get the
>authors to apply this principle?

I don't know of ANY Java textbook except _How to Design Class 
Hierarchies_ that follows this rule, but I would encourage the 
authors on this list to do so.

BTW, for those who use the BlueJ CheckStyle plug-in, I wrote a 
CheckStyle rule named "RequireThis" (incorporated into the last 
several releases of CheckStyle) which flags expressions that rely on 
the "automatic this" shortcut.  You can specify that it applies to 
fields, methods, both, or neither.  It has one known bug -- it 
sometimes flags references to static fields and methods -- which I 
haven't gotten around to fixing, but if you're giving your students a 
CheckStyle style file anyway, here's another one to include.
-- 
Dr. Stephen Bloch
Math/CS Department
Adelphi University
sbloch at adelphi.edu



More information about the bluej-discuss mailing list