HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaModerate

Arguments in constructors matching fields

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
constructorsargumentsmatchingfields

Problem

What is your opinion in arguments in constructors matching members as in the following example

public Join(final int parent, final TIntHashSet children) {
  this.parent = parent;
  this.children = children;
}


I find this annoying since I have to use this. and also some code review applications generate warnings.

Solution

I've personally always found the _parent or Hungarian-notation letters at the beginning far uglier than just saying this. this is very straightforward, especially if somebody else is reading your code. If I inherit somebody else's code and they use _ I change it immediately.

Context

StackExchange Code Review Q#471, answer score: 12

Revisions (0)

No revisions yet.