传递整个对象与传递原始值是否存在开销或性能问题,如选项1和2中所示?
[编辑:我的意思是说传递Java对象与原始类型的引用.来自@TJ Crowder,我知道这里没有性能问题,因为两种情况下对象引用大小都相同.但是API设计风格/视角的中介,哪个选项是最好的?]
我目前正在定义服务层.我更喜欢"Type 1",但如果'Type 2'对性能有好处,我会选择Type 2.
Class A {
User user = SomeClass.getUser("anUser");
B b = new B();
b.doSomeOperation(user); // option 1
b.doSomeOperation(user.getUserId()); // option 2
}
Class B {
// Type 1
public void doSomeOperation(User user){
// some work done by using user.getUserId()
// I do not really need whole user object now.
}
// Type 2
public void doSomeOperation(int userId){
// some work done by userId
}
}
Run Code Online (Sandbox Code Playgroud) 我之前在我的 Spring 应用程序中使用过基于 XML 的配置。
现在,我只想使用@ Bean、@Configuration 等基于 Java 的容器配置。
如何将这两段 XML 配置转换为基于 Java 的配置?
<outbound-channel-adapter channel="emailChannel" ref="messageHandler">
<poller>
<interval-trigger interval="60000"/>
</poller>
</outbound-channel-adapter>
<tx:annotation-driven transaction-manager="transactionManager"/>
Run Code Online (Sandbox Code Playgroud)