java instance implements property sharing. For example, I now have a 10 million-word loop, and I need to change the property in an instance to I
.the code is as follows
List<OrderInfo> orderInfos = new ArrayList<OrderInfo>();
OrderInfo orderInfo=null;
for(int i=0;i<10000000;iPP){
orderInfo = new OrderInfo();
orderInfo.setOrderState(i);
orderInfos.add(orderInfo);
}
if orderInfo is mentioned, an object will be referenced
orderInfo = new OrderInfo();
for(int i=0;i<10000000;iPP){
orderInfo.setOrderState(i);
orderInfos.add(orderInfo);
}
the problem is very simple. If the attributes in my object are very complex and heavy, then the rest of the attributes are wasted
. Is there any way to share other attributes and be independent of orderState, which can save a lot of memory? please give us some advice when entering java, for the first time. Thank you