假设两个类
class A{
  int a[];
  B b;
  public void pro_a(){
   //处理b.b1.......
   }
 //...
 
  
}
class B{
 public static  int b1[];
 B(){b1=new int[50000];...
}----------------------------------------------
另一段代码是:
class A{
  int a[];
  public void pro_a(B b){
   //处理b.b1.......
   }
 //...
 
  
}
class B{
 public static  int b1[];
 B(){b1=new int[50000];...
}一个是在对象中组合使用,一个通过参数调用,这两种性能哪一个优?

解决方案 »

  1.   

    没有性能区别。至少还没到可以考虑性能的时候。第二种的耦合性比较底,一般来讲在设计上会好些,但是还要看具体应用。class B 里面有一个public static int b1[],是一个相当糟糕的设计,而且每次产生B对象的时候竟然要对数组重新赋值,这个性能损失不起。对于这样糟糕的设计,请不要考虑性能。改善设计会带来更好性能的。