In a constructor designed to assign values to class variables when creating an object, I sometimes use this. , sometimes not used. I checked - both options work, is one of them preferred?
public class Vehicle { private String color; Vehicle(String c) { color = c; } } public class Vehicle { private String color; Vehicle(String c) { this.color = c; } }
thisusually omitted (not used) if its use is not explicitly required (reference to the same-name class fields and local variables, for example) - pavlofff