日期:2014-05-20 浏览次数:21273 次
/**
* 方法解析添加了注解的类,并将类的一些信息(如 作用域,配置名称)添加并返回。
* @param packagePath 该类的全路径(包括包名)
* @return 如果该类上有SpringBeanClass的注解,那么给这个类赋值并返回类的实例,如果该类没有添加注解,则返回null
*/
private ClassBean getClassBeanInfo(String packagePath){
ClassBean cb = null;
String path = packagePath.substring(0, packagePath.lastIndexOf(".class"));
Class<?> bean = null;
try {
bean = Class.forName(path);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
SpringBeanClass classBean = bean.getAnnotation(SpringBeanClass.class); // 获取该类上面的注解类实例
if(classBean != null){
cb = new ClassBean();
/**为scope设置值,默认为single模式的---------begin*/
String scope = classBean.scope();
if(scope == null || scope.equals("")){ // 如果scope没有设置值,即为默认值时,scope设置为single模式的
scope = "single";
}
/**为scope设置值,默认为single模式的---------end*/
/**为xmlName设置值,默认为该类的类名首字母小写---------begin*/
String xmlName = classBean.name();
if(xmlName == null || xmlName.equals("")){ // 如果scope没有设置值,即为默认值时,scope设置为single模式的
xmlName = SpringUtil.firstWordLowerCase(SpringUtil.spiltClassName(path)); //默认为该类的类名首字母小写
}
/**为xmlName设置值,默认为该类的类名首字母小写---------end*/
cb.setPath(path);
cb.setScope(scope);
cb.setXmlName(xmlName);
}
return cb;
}
------解决方案--------------------
体现出当前水平的代码不一定就是代码的难度系数高吧,写个helloWorld加上注释和捕捉具体异常,提高效率代码简洁都可以展现水平把
------解决方案--------------------
很简单。用*打个3行5列的矩证。
新手会用 双重循环。
老手会用 三句 print。
日式程序员 会把 * ,3和5 定义常量
国内高手会把代码写得你看不懂 例如:
for(int i=0;i<=3*(5+1);i++) System.out.print((char)(i%(5+1)==0?13:42));
------解决方案--------------------
这道考题太失败了,代码决定不了水平
如果是,举例你看到过或写过的你个人觉得比较好的代码(包括代码组织,设计思想,逻辑思维,算法等),还说的过去
所以对于这样的考题,是我的话我就如此回答
public class SimpleIsBest {
public static void main(String[] args) {
System.out.printf("这道考题太失败,太有水平的代码你看不懂,还是你直接评价吧: %s\n", (args.length==0 ? "不评价" : args[0]));
}
}
------解决方案--------------------
感觉这个问题还不错,有时看看一些很NB的代码,还是感触很深的。也不能完全否认从这个角度来判断你的能力。我这里也写一段吧,也是看别人的,感觉挺好,也会在实际工作中使用:
public String[] contents = new String[10];
public synchronized void put(String content){
/**
* 这里用while而不是用if,放置线程假醒的情况!
*/
while(contents.length == 10){
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
那段while用得感觉挺好!