项目经理大神写出的代码,各位大神有何看法 sendDate -> sendDataROUNDINGMODE -> ROUNDING_MODE 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 新手说说个人疑问:1.为什么把常量定义为private,定义为public不更好吗?2.定义常量ROUNDINGMODE = BigDecimal.ROUND_HALF_DOWN有意义吗? BigDecimal.ROUND_HALF_DOWN本身就是一个常量 小伙子,你说的第二个疑问我也有,但是第一个我并不认为这样做有什么不妥。面向对象中的迪米特法则,就是优先让变量作用域最少,除非有必要,才将private变成protect甚至public 楼上是要表达 extends 和 implements 一起用么?我这也有这样的代码:import org.aopalliance.aop.Advice;import org.springframework.aop.Advisor;import org.springframework.aop.TargetSource;import org.springframework.aop.framework.AopInfrastructureBean;import org.springframework.aop.framework.ProxyConfig;import org.springframework.aop.framework.ProxyFactory;import org.springframework.aop.framework.autoproxy.AutoProxyUtils;import org.springframework.aop.support.AopUtils;import org.springframework.aop.target.SingletonTargetSource;import org.springframework.beans.factory.BeanClassLoaderAware;import org.springframework.beans.factory.BeanFactory;import org.springframework.beans.factory.BeanFactoryAware;import org.springframework.beans.factory.InitializingBean;import org.springframework.beans.factory.config.BeanPostProcessor;import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import org.springframework.core.Ordered;import org.springframework.core.PriorityOrdered;import org.springframework.util.ClassUtils;public class CacheableProxyCreator extends ProxyConfig implements BeanClassLoaderAware, BeanFactoryAware, BeanPostProcessor, PriorityOrdered, InitializingBean { private static final long serialVersionUID = 1L; private static final Class<?>[] INFRASTRUCTURE_CLASSES = { Advice.class, Advisor.class, AopInfrastructureBean.class }; private final transient Log log = LogFactory.getLog(getClass()); /** * BeanFactory instance, the object is injected by spring container automatically */ private transient BeanFactory beanFactory; /** * BeanFactoryClassLoader instance, the object is injected by spring container automatically */ private transient ClassLoader classloader; /** * Handpay cacheable annotation advisor */ private CacheablePointcutAdvisor advisor; /** * Ignore bean names that create handpay cacheable proxy object */ private String[] ignoreBeanNames; 第二个原因是java中double型数据的小数位过多时转化时会出错,也就是精确度不够,所以需要BigDecimal来保证精确度,这在金额中很常见 第二个原因是java中double型数据的小数位过多时转化时会出错,也就是精确度不够,所以需要BigDecimal来保证精确度,这在金额中很常见虽然 BigDecimal.ROUND_HALF_DOWN就是常量,但是这样定义也没有问题吧。如果下面用很多次BigDecimal.ROUND_HALF_DOWN的话代码就短了很多啊,而且他用了注释,下面的这个变量鼠标一移过去就会看到注释啊,别人一看就知道这个变量的作用。还有可能以后要改变舍入模式的话改这个变量就行了啊。纠结这些有什么意思呢,可能就是你项目经理的代码习惯问题吧,而且是挺好的编程习惯。 关于第二条,这样做法很正常,也是不错的习惯,看java的源码中有很多这样的做法。这样做的好处:1、可以减少代码量,使代码看起来更清晰,2、有助于代码的阅读和使用,别人一看大致就能明白它在在里表示什么意义. 多线程 spring controller打包jar J2EE架构师手册 mina2.0如何传输文件? 国际化 hibernate插入出错!找了很久都没有找出原因,很急!请高手帮忙! 如何将word中的数据导入到jsp页面中?100分 struts2种配置json JSP文件中,两个SQL语句嵌套在一起,执行不了,请帮忙看看~~ 一个DTD的问题 PDF在网页html中该如何控制显示模式 java后台数据校验框架你会选择哪个???
1.为什么把常量定义为private,定义为public不更好吗?
2.定义常量ROUNDINGMODE = BigDecimal.ROUND_HALF_DOWN有意义吗? BigDecimal.ROUND_HALF_DOWN本身就是一个常量
import org.springframework.aop.Advisor;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.AopInfrastructureBean;
import org.springframework.aop.framework.ProxyConfig;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.SingletonTargetSource;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.util.ClassUtils;public class CacheableProxyCreator extends ProxyConfig implements BeanClassLoaderAware, BeanFactoryAware,
BeanPostProcessor, PriorityOrdered, InitializingBean { private static final long serialVersionUID = 1L; private static final Class<?>[] INFRASTRUCTURE_CLASSES = { Advice.class, Advisor.class, AopInfrastructureBean.class }; private final transient Log log = LogFactory.getLog(getClass()); /**
* BeanFactory instance, the object is injected by spring container automatically
*/
private transient BeanFactory beanFactory; /**
* BeanFactoryClassLoader instance, the object is injected by spring container automatically
*/
private transient ClassLoader classloader; /**
* Handpay cacheable annotation advisor
*/
private CacheablePointcutAdvisor advisor; /**
* Ignore bean names that create handpay cacheable proxy object
*/
private String[] ignoreBeanNames;
第二个原因是java中double型数据的小数位过多时转化时会出错,也就是精确度不够,所以需要BigDecimal来保证精确度,这在金额中很常见
第二个原因是java中double型数据的小数位过多时转化时会出错,也就是精确度不够,所以需要BigDecimal来保证精确度,这在金额中很常见虽然 BigDecimal.ROUND_HALF_DOWN就是常量,但是这样定义也没有问题吧。如果下面用很多次BigDecimal.ROUND_HALF_DOWN的话代码就短了很多啊,而且他用了注释,下面的这个变量鼠标一移过去就会看到注释啊,别人一看就知道这个变量的作用。还有可能以后要改变舍入模式的话改这个变量就行了啊。纠结这些有什么意思呢,可能就是你项目经理的代码习惯问题吧,而且是挺好的编程习惯。