compareTo:
如果指定的数与参数相等返回0。
如果指定的数小于参数返回 -1。
如果指定的数大于参数返回 1。
内存数据量过大,用ConcurrentHashMap
数组初始化:
int[] a = {1,2,3};
int[] a = new int[2];
/************************************反射机制开始***************************************************/
/**
* 获得对象值
*
* @param psid
*/
public Object getIvalue(DaDaydataJb dayJb, Integer i) throws Exception {
Class jbCla = DaDaydataJb.class;
Method method = jbCla.getDeclaredMethod("getI" + i);
return method.invoke(dayJb);
}
/**
* 获得扩展实体对象值
*
* @param psid
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public Double getIvalue(DaHisDataPiExtEntity hisData, Integer i) throws Exception {
Class boxclass = DaHisDataPiExtEntity.class.getSuperclass();
Method method = boxclass.getDeclaredMethod("getDci" + i);
Double result = (Double) method.invoke(hisData);
return result;
}
/**
* 根据对象的属性名,获取对象中值
*
* @param form 对象
* @param property 属性名
* @return 属性的值
* @throws Exception 异常信息
*/
public static Object getObjectByGetMethod(Object form, String property) throws Exception {
Object value = null;
// 创建类对象
Method method = form.getClass().getDeclaredMethod("get" + StringUtil.toFirstLetterUpperCase(property));
// 获取值
value = method.invoke(form, new Object[] {});
// 返回
return value;
}
/**
* 将首字符大写
*
* @param str
* 字符串
* @return 首字符大写的字符串
*/
public static String toFirstLetterUpperCase(String str) {
if (StringUtil.isNotEmpty(str)) {
String firstLetter = str.substring(0, 1).toUpperCase();
return firstLetter + str.substring(1, str.length());
} else {
return str;
}
}
/**
* 用户操作的展示模块
* @param userid
* @param tag
* @param tagval
* @throws Exception
*/
public void saveMainShow(Integer userid,String tag,Integer tagval) throws Exception{
AppMainShow appMainShow = ***;
if(appMainShow == null){
appMainShow = new AppMainShow();
appMainShow.setUserid(userid);
}
Field f = appMainShow.getClass().getDeclaredField(tag);
f.setAccessible(true);
f.set(appMainShow, tagval);
daoSrv.saveOrUpdate(appMainShow);
}
/************************************反射机制结束***************************************************/
public interface TestInterface {
void add();;
}
public class TestInterfaceImpl implements TestInterface {
@Override
public void add() {
System.out.println("我是add的方法!!!");
}
}
用法:TestInterface test = new TestInterfaceImpl();
【cglib代理类和实现类之间是父子关系,自然可以用父类(实现类)去接收子类对象(代理类对象即增强类对象)。
不过应该不会需要这么做,使用接口本来就是解耦的,你直接用实现类接收注入对象岂不是失去了注入的意义。(为什么不直接new一 个呢?)】
static方法就是没有this的方法。在static方法内部不能调用非静态方法,反过来是可以的。而且可以在没有创建任何对象的前提下,仅仅通过类本身来调用static方法。这实际上正是static方法的主要用途。
方便在没有创建对象的情况下来进行调用(方法/变量)。
很显然,被static关键字修饰的方法或者变量不需要依赖于对象来进行访问,只要类被加载了,就可以通过类名去进行访问。
static可以用来修饰类的成员方法、类的成员变量,另外可以编写static代码块来优化程序性能。
工作中遇到java相关关键字用法
最新推荐文章于 2021-09-14 11:44:08 发布