在
Java中,我可以将本地“变量”声明为最终的.
- void myMethod() {
- final String foo = "Hello World!";
- foo = "Bye-bye..."; // compile error!!
- return;
- }
当我尝试改变它的值时,从编译器得到一个错误.我想要声明一些我本地的“变量”,以避免意外地改变它们的价值.
Objective-C有可能吗?
解决方法
像C/C++一样,使用const关键字.
更多信息,这篇文章似乎在你的胡同:Java Developer’s Guide to String Constants in Objective-C