Java中的不可变类(Immutable class in Java)
根据许多文档,我已经看到一个不可变类应该具有以下特征:
上课应该是最后的
所有的方法应该是最终的
所有的变量应该是最终的
不应该有任何制定者
但我的问题是:
如果我有一个只有最终变量的类,该怎么办?
如果我也有setter,我不能改变Object的状态,因为我有所有的最终变量。 那么这将如何影响不变性?
在这种情况下继承如何改变对象状态?
As per many documentations, I have seen that an immutable class should have the following features:
class should be final
all the methods should be final
all the variables should be final
there should not be any setters
But my questions are:
What if I have a class with only final variables?
If I do have setters also, I cannot change the state of the Object as I have all the final variables. So how will this affect immutability?
How can inheritance change the object state in this case?
原文:https://stackoverflow.com/questions/28984664
满意答案
找到了将对象转换为数组的方法
var nArray = jQuery.makeArray(s);
工作
found the method to convert object to array
var nArray = jQuery.makeArray(s);
worked
相关问答
更多离子3 - 想要将对象数组转换为控制器中的字符串数组(Ionic 3 - Want to convert array of object to array of strings in controller)
如何使用ajax发布到Symfony2中的安全控制器(how to post with ajax to secured controller in Symfony2)
ajax将一串字符串发布到控制器(ajax post an array of strings to controller)
Ajax仅将第一个字符串数组的索引返回给Spring控制器(Ajax returns only first index of stringified array to the Spring controller)
使用AJAX更新Rails列,该列需要字符串数组(Update Rails column that expects array of strings using AJAX)
MVC控制器的替代方法返回字符串的操作?(Alternatives to MVC Controller Actions returning strings?)
为什么发布数据完全空了通过ajax发布到CodeIgniter控制器?(Why is post data completely empty posting to CodeIgniter controller via ajax?)
将带有字符串的json数组发布到Asp.Net MVC操作控制器始终为null(Posting json array with strings to Asp.Net MVC action controller is always null)
Post方法一个文件和字符串请求到弹簧休息控制器接收字节[]和字符串使用角?(Post method a file and string request to spring rest controller that receive byte[] and Strings using angular?)
如何使用ajax将字符串数组传递给控制器?(How to pass string array to controller using ajax?)
相关文章
更多java反射详解(一)_Class类
Guava学习笔记:Immutable(不可变)集合
如何卸载assembly?或者class
mybatis There is no getter for property named 'xx' in 'class java.lang.String
Java泛型父类取得子类的泛型参数T的Class类型
ssh 框架下 class 类打包发布
【原】storm源码之一个class解决nimbus单点问题
Java 抽象类
Java String类
Java对象和类
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!