【程序员摄影】之世博公园

立春这一天本程序狗带着相机出门采风了,因为刚买的相机有点小兴奋。出了门才发现上海的冬天真不是盖的,天上的太阳仿佛是假的一般,冻的人瑟瑟发抖。风有点大,公园人不多,偶尔来个人也是跑步的,拿着我的fijifilm xt20随手拍的,感觉我仿佛买的事是假相机,照片跟手机拍的一样。 下面的照片都是直出,没有经过后期处理,还需要多加学习呀。

散文随笔

2017年总结

业务上,从刚开始对供应链几乎没什么了解,到现在基本上熟悉了供应链的各个环节,包括订单的正逆向流转的各个环节,库存包括一件货物的生命周期整个流转过程,采购到退仓,一退二退三退等,供应商部分:供应商入住,框架合同,品牌授权等。业务上能够及时向相关接口人咨...

年终总结

昨天是二十四节气的霜降,这才感觉到秋天的已经快要离我而去,因为霜降接下来就是立冬了,晚上出去跑步已经不能穿短袖短裤了,秋天,这个收获的季节,我收获了什么果实,我在想… 最近工作上的事情把自己压得够呛,从国庆节过来开始到现在,每天都保持在基本后半夜才能...

散文随笔

Atom优秀package列表(持续更新)

Atom,VSCode 都属于Electronic 构建的跨平台编辑器,Atom 属于Github,VSCode属于Microsoft,两个的开源软件在社区里都挺活跃,Sublime也挺好用的,特别是速度,完爆Atom,VSCode 速度要比Atom...

工具效率

2017年中总结

如约而至的七月,空气里充满了茂盛的味道,狂风、暴雨、烈日、蝉鸣… 分外怀念有暑假的日子。2017年已经过了一半,白天时间开始变短,下半年也逐渐开始了,是时候给自己的上半年总结一下了。总结是为了更好的了解自己的途径,成长也许就在不经意之间就发生了,同时...

年终总结

自律与健康

自律给我自由 一直很喜欢Keep启动时splash上这句话,使用Keep这个软件也1年多了,想总结点东西。 其实最早用keep是2015年的8月,只不过那时候Keep还没有跑步的功能,而我也一直在用悦跑圈跑步,整个从2015年7月开始到2016年...

散文随笔

开始自己的Mac人生

拥有一台mac应该算是从学生时代的愿望,但是苦于囊中羞涩,工作了之后想买但是自己又下不去狠心去买,618期间本来想入手15款的macbook pro,跟女朋友一说这个事情,她说要买就买最新款的,不差那几个钱,所以昨天就和她一起去南京东路苹果直营店买下...

散文随笔

Java中final关键字总结

final在java中的用法有很多,可以修饰field,可以修饰Method,可以修饰Class,而且final在多线程环境中保证了对象状态的不变性,下面就系统的总结一下Java中final关键字的用法 修饰Variable/field 修饰primitive变量,变量一旦赋值就不再可变。 final修饰基本数据类型变量和String类型时,类似于C++的const 3种变量会被隐式的定义为final:3.1. 接口中的field是final的3.2. Java7中出现的try with resource语句中的变量是隐式的final类型,如下面的代码,inputStream虽然未被声明为final,但是如果试图在try块里面重新对inputStream赋值的话,就会产生编译异常,不能给final变量赋值 12345try (FileInputStream inputStream = new FileInputStream("text.txt")){inputStream = new FileInputStream("");} catch (Exception e) { e.printStackTrace();} 修饰引用实例类型变量,变量被赋值后,变量指向的引用的值可以变,但是不能重新指向新的引用,即final只关心引用本身,而不关心final引用的内容。 12345678public static void main(String[] args) { final User user = new User("xuan1",23); System.out.println(user.getAge()); //输出23 user.setAge(24); System.out.println(user.getAge()); //输出24 user = new User("xuan2",25); //编译错误,提示不能赋值给final变量 System.out.println(user.getAge());} 修饰实例成员变量时,必须在定义的时候初始化:直接赋值,构造器初始化,或代码块中初始化,或的意思是这三种方式只能选择一种,否则编译报错。 修饰静态成员变量时,必须在变量定义的时候初始化:直接赋值,静态代码块中赋值 Tips: 有一种特殊情况:System.in,System.out,System.err 是静态域但是没有在定义的时候或者静态代码块中初始化,而是使用了set方法来设置值。 JDK8以前内部类访问外部类的变量时要求变量为Final类型,JDK8之后,只要求外部类为事实不可变变量,不一定要加上final

java

intellij idea中使用javap等JDK工具

java工程师平时工作中用到的工具挺多的,比如javap,jstack等,intellij idea 作为宇宙最强java ide idea一样可以帮我们实现这个功能,方法如下: ctrl+alt+s打开设置界面,找到Tool-> External Tools 点击 +来增加一个新的外部工具。

java

Java中将JSON反序列化为泛型对象

将嵌套List的Map转换为Json应该都没什么问题,使用Gson和Jackson都能实现,在Gson中使用new Gson().toJson()方法,在Jackson中使用new ObjectMapper().writeValueAsString()即可。将json转换为形如Map<String,List>的时候遇到了一点问题,虽然返回类型是Map<String,List<Long>>但是,Map的value的值却并不是List<Long>,而是Integer类型的,这里面显然是有问题的,查看Jackson的源码和Gson的源码发现将json反序列化为对象确实有两个方法,一种适用于泛型对象,一种适用于非泛型的一般对象。 使用Gson在gson中将json字符串转反序列化为对象有两个方法: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 /** * This method deserializes the specified Json into an object of the specified class. It is not * suitable to use if the specified class is a generic type since it will not have the generic * type information because of the Type Erasure feature of Java. Therefore, this method should not * be used if the desired type is a generic type. Note that this method works fine if the any of * the fields of the specified object are generics, just the object itself should not be a * generic type. For the cases when the object is of generic type, invoke * {@link #fromJson(String, Type)}. If you have the Json in a {@link Reader} instead of * a String, use {@link #fromJson(Reader, Class)} instead. * * @param <T> the type of the desired object * @param json the string from which the object is to be deserialized * @param classOfT the class of T * @return an object of type T from the string. Returns {@code null} if {@code json} is {@code null}. * @throws JsonSyntaxException if json is not a valid representation for an object of type * classOfT */public <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { Object object = fromJson(json, (Type) classOfT); return Primitives.wrap(classOfT).cast(object); } /** * This method deserializes the specified Json into an object of the specified type. This method * is useful if the specified object is a generic type. For non-generic objects, use * {@link #fromJson(String, Class)} instead. If you have the Json in a {@link Reader} instead of * a String, use {@link #fromJson(Reader, Type)} instead. * * @param <T> the type of the desired object * @param json the string from which the object is to be deserialized * @param typeOfT The specific genericized type of src. You can obtain this type by using the * {@link com.google.gson.reflect.TypeToken} class. For example, to get the type for * {@code Collection<Foo>}, you should use: * <pre> * Type typeOfT = new TypeToken&lt;Collection&lt;Foo&gt;&gt;(){}.getType(); * </pre> * @return an object of type T from the string. Returns {@code null} if {@code json} is {@code null}. * @throws JsonParseException if json is not a valid representation for an object of type typeOfT * @throws JsonSyntaxException if json is not a valid representation for an object of type */ @SuppressWarnings("unchecked") public <T> T fromJson(String json, Type typeOfT) throws JsonSyntaxException { if (json == null) { return null; } StringReader reader = new StringReader(json); T target = (T) fromJson(reader, typeOfT); return target; }

java
14567810

本站由 Hank Zhao 使用 Stellar 主题创建。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
本站总访问量