Alias | Command | What to Type |
---|---|---|
git cleanup | git branch --merged | grep -v '*' | xargs git branch -d |
git config --global alias.cleanup "!git branch --merged | grep -v '*' | xargs git branch -d" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
public class GenericArray <E> { | |
E[] items; | |
Object[] objs; | |
public static void main(String[] args) { | |
Integer[] intArray = {1, 2, 3}; | |
Double[] doubleArray = {1.0, 2.0, 3.0}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class GenericSuperBasic { | |
public static void main(String[] args) { | |
List<? super Integer> superIntList = new ArrayList<Number>(); | |
superIntList.add(10); | |
// Integer intValue = superIntList.get(0); | |
Object objValue = superIntList.get(0); | |
Integer intValue = (Integer) objValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
import java.util.Iterator; | |
import java.util.List; | |
public class GenericExtendClass { | |
public static void main(String[] args) { | |
GenericArrayList<Integer> myIntList = new GenericArrayList<>(); | |
myIntList.put(1); | |
System.out.println(myIntList.get()); | |
myIntList.add(10); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenericExtendBasic { | |
public static void main(String[] args) { | |
Container<Apple> apple = new Container<>(); | |
Container<Banana> banana = new Container<>(); | |
// Container<TV> tv = new Container<>(); compiler error | |
} | |
} | |
class Fruit {} | |
class Apple extends Fruit{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenericMethod { | |
public static <T> T elementOf(T[] objects, int index) { | |
return objects[index]; | |
} | |
public static void main(String[] args) { | |
String[] data = {"aaa", "bbb", "ccc"}; | |
String a = GenericMethod.elementOf(data, 0); | |
System.out.println(a); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
public class MyStringComparator implements Comparator<String> { | |
@Override | |
public int compare(String s1, String s2) { | |
return -s1.compareTo(s2); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class MyArrayList<E> { | |
private Object[] elements; | |
private int next; | |
public MyArrayList(int capacity) { | |
elements = new Object[capacity]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class BasicGenericDemo { | |
public static void main(String[] args) { | |
// without generic | |
List listWithoutGeneric = new ArrayList(); | |
listWithoutGeneric.add("test"); | |
Integer i = (Integer) listWithoutGeneric.get(0); // runtime exception |
- 導論 | 文/李延華 | 2006-02-13 發表
- 建立檢查清單,以防掛一漏萬 | 文/iThome | 2006-02-08 發表
- 人事篇 | 文/iThome | 2006-01-27 發表
- 系統維運篇 | 文/張明德 | 2006-02-14 發表
- 機房管理:平時如戰時,戰時如平時 | 文/劉人豪 | 2006-02-16 發表
- 資安篇 | 文/蘇碩鈞 | 2006-02-14 發表
- 辦公室作業應變篇 | 文/張瑞隆 | 2006-02-14 發表
NewerOlder