Possible Duplicate:
Java - when to use this keyword
用这个引用类属性通常是个好约定吗。即使默认情况下会引用该属性?或者我应该只在绝对必要的时候使用它?
这将使程序员更清楚地了解情况,并避免在程序员添加任何具有相同名称的新变量时出现任何令人困惑的错误。
Possible Duplicate:
Java - when to use this keyword
用这个引用类属性通常是个好约定吗。即使默认情况下会引用该属性?或者我应该只在绝对必要的时候使用它?
这将使程序员更清楚地了解情况,并避免在程序员添加任何具有相同名称的新变量时出现任何令人困惑的错误。
有些人有一个约定,让私有成员变量在前面或后面加下划线。在这些情况下,很明显this
是隐含的。
如果您没有私有成员的命名约定,那么this
是指示您正在读/写的变量是成员变量的好方法。
我不希望任何具有不同作用域(参数、成员、局部变量)的变量共享相同的名称。我通过为成员命名的惯例来避免这种情况。
Use it in copy constructors and other instances where you must. Eg:
Foo(Foo rhs) {
this.bar = rhs.bar;
this.baz = rhs.baz;
}
大多数现代IDE都会对成员变量进行颜色编码,因此您可以将它们与args区分开来。或者,您可以使用一种命名方案,让您知道成员是什么,例如在前面加上m_。
最好不要将args命名为与成员变量相同的名称,这样就不会遇到这样的冲突。
高。
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...