作者:吴钧隆362 | 来源:互联网 | 2023-01-26 18:27
假设我需要访问变量'asdf'大约1000次.
什么会更快:创建对象Foo并将其作为参数传递给bar构造函数并通过getter访问它或静态访问Foo的数字.或者那两种方法具有相同的性能?
Class Foo {
public int asdf;
}
Class Bar {
Foo foo;
Bar(Foo foo1) {
this.foo = foo;
}
public void funcBar() {
foo.asdf;
}
}
Class Foo {
public static int asdf;
}
Class Bar {
public void funcBar() {
Foo.asdf;
}
}
GhostCat say..
7
1000次没什么.
因此,您编写了使用直接和"干净"方式完成工作的代码.
担心好的设计而不是浪费时间来解决不存在的性能问题.
1> GhostCat say..:
1000次没什么.
因此,您编写了使用直接和"干净"方式完成工作的代码.
担心好的设计而不是浪费时间来解决不存在的性能问题.