Created
February 10, 2013 13:09
-
-
Save jakubjanecek/4749536 to your computer and use it in GitHub Desktop.
This file contains 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
private static int genericSize(Object obj) { | |
if (obj instanceof String) { | |
String s = (String) obj; | |
return s.length(); | |
} else if (obj instanceof int[]) { | |
int[] a = (int[]) obj; | |
return a.length; | |
} else if (obj instanceof List) { | |
List l = (List) obj; | |
return l.size(); | |
} else if (obj instanceof ObjectWithSize) { | |
ObjectWithSize o = (ObjectWithSize) obj; | |
return o.count(); | |
} else { | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment