spring
| msg | link | |
|---|---|---|
| spring 中的标准缓存如何写的呢 | link | |
| link | ||
| link | ||
| link | ||
| link | ||
| link | ||
| link | ||
| link | ||
| link | ||
| link | ||
| link | ||
| link |
匿名实现接口
public class DemoInterface
{
public static void main(String[] args) {
Runner r=new Runner() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("我是匿名的,但是我会跑。。。");
}
};
r.run();
}
}
使用final 来加快工具类的速度
package com.streamax.basePlatForm.util;
/**
* 系统常量定义
* @author slpan
* @date 2018年8月15日 下午3:39:19
*/
public class SystemConstant {
public static final int RESPONSE_CODE_200 = 200;//正常
public static final int RESPONSE_CODE_201 = 201;//参数错误
public static final int RESPONSE_CODE_202 = 202;//服务器错误
public static final int RESPONSE_CODE_203 = 203;//没有权限
public static final int RESPONSE_CODE_204 = 204;//认证不通过
public static final int RESPONSE_CODE_205 = 205;//用户名或密码错误
public static final int RESPONSE_CODE_206 = 206;//账号已过期
public static final int RESPONSE_CODE_207 = 207;//token过期
public static class Config {
/**
* 自动加车默认应用key
*/
public final static String AUTO_ADD_VEHICLE_APP_KEY = "auto.add.vehicle.app.key";
/**
* 黑白名单模式配置
*/
public final static String BLACK_WHITE_MODE = "black.white.mode";
/**
* 企业层级限制
*/
public final static String COMPANY_LEVEL_LIMIT = "company.level.limit";
}
}
这段代码的好处在于使用了 final static 修饰一堆常量,可以使用java的内联机制,加快效率;缺点当然是常驻内存之中,如果没有new,每次都是点出来
通过 reference 获取能力,比继承获取能力更加灵活


本文探讨了Java中使用final静态常量优化工具类速度的方法,以及Spring框架中标准缓存的实现技巧。通过具体代码示例,展示了如何利用final关键字提升程序效率,并介绍了Spring缓存的编写方式。
2220

被折叠的 条评论
为什么被折叠?



