跳到主要內容

第一篇

很久沒寫網誌這種東西了,
年紀大了其實不是腦子記憶體空間不足
而是生活中太多雜事需要紀錄
那就來記錄一下吧~

留言

這個網誌中的熱門文章

Java String Format

java練習筆記 String Format延伸應用: fix position : left justified()           System.out.println(String.format("%-10s hello" , s1));           hello      java fix position : right justified()           System.out.println(String.format("%10s helllo" , s1));                hello java fill zero in front           String.format("%03d" ,  s1)           050

Java-取出物件memory大小

import org.apache.lucene.util.RamUsageEstimator; String b = "hello warld!"; System.out.printf("sizeOf(String) = %s bytes\n", RamUsageEstimator.sizeOf(b)); //pom.xml 新增jar <dependency> <groupId>fakepath</groupId> <artifactId>lucene-core</artifactId> <version>4.2.0</version> </dependency>

JAVA 泛型的基本運用

今日遇到一個case,剛好適合運用泛型,因此紀錄一下。 假設情境是這樣的: class A 要實作加密跟解密兩個method,然後會使用到物件 dto A, class B 也要實作加密跟解密兩個method,然後會使用到物件 dto B, 清楚地,因為兩個class都會實作到相同的method,但必須使用到專屬自己要用的物件(dto),所以這邊可以使用泛型(T)來假裝欲套用的型別來給介面使用.後續該物件在實作時則帶入欲使用的dto即可. public interface Vehicle<T> { public T show(T other); public List<T> shows(List<T> others); } public class ACar implements Vehicle<Adto>{ @Override public Adto show(Adto other) { System.out.println(other.getName()); return other; } @Override public List<Adto> shows(List<Adto> others) { for(Adto adto : others) { System.out.println(adto.getName()); } return null; } } public class Adto { String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } ...