Created
March 17, 2015 02:22
-
-
Save agusbrand/5fd44c7729f3eeae580f to your computer and use it in GitHub Desktop.
color sintaxis p google docs
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
Integer iNum = new Integer(123); | |
String sText = "The number one-two-three = "; | |
String sFullText = sText + iNum; // aca llama al toString, es al pedo ponerlo o no. | |
/** | |
* This method simply throws an Exception if the incoming parameter a is not a positive number, just for fun. | |
* | |
* @param shouldThrow Whether or not to throw an exception | |
* @throws Exception | |
*/ | |
public void throwException(boolean shouldThrow) throws Exception | |
{ | |
if(shouldThrow) | |
{ | |
throw new Exception(); | |
} | |
} | |
String sClassName = "android.app.NotificationManager"; // No pongo el import de la clase :) | |
try { | |
Class classToInvestigate = Class.forName(sClassName); | |
// Dynamically do stuff with this class | |
// List constructors, fields, methods, etc. | |
} catch (ClassNotFoundException e) { | |
// Class not found! | |
} catch (Exception e) { | |
// Unknown exception | |
} | |
Constructor[] aClassConstructors = classToInvestigate.getDeclaredConstructors(); | |
for(Constructor c : aClassConstructors){ | |
// Found a constructor c | |
// Object asd = c.newInstance() | |
} | |
Field[] aClassFields = classToInvestigate.getDeclaredFields(); | |
for(Field f : aClassFields){ | |
// Found a field f | |
} | |
String sClassName = "android.content.Intent"; | |
try { | |
Class classToInvestigate = Class.forName(sClassName); | |
String strNewFieldName = "EXTRA_CHANGED_PACKAGE_LIST"; | |
Field newIn22 = classToInvestigate.getField(strNewFieldName); | |
} catch (ClassNotFoundException e) { | |
// Class not found | |
} catch (NoSuchFieldException e) { | |
// Field does not exist, likely we are on Android 2.1 or older | |
// provide alternative functionality to support older devices | |
} catch (SecurityException e) { | |
// Access denied! | |
} catch (Exception e) { | |
// Unknown exception | |
} | |
Method[] aClassMethods = classToInvestigate.getDeclaredMethods(); | |
for(Method m : aClassMethods) | |
{ | |
// Found a method m | |
} | |
int permissions = classToInvestigate.getModifiers(); | |
if(Modifier.isPublic(permissions)) { | |
// Class is Public | |
} | |
if(Modifier.isProtected(permissions)) { | |
// Class is Protected | |
} | |
if(Modifier.isPrivate(permissions)) { | |
// Class is Private | |
} | |
String sClassName = "android.widget.AbsoluteLayout"; | |
try { | |
Class classToInvestigate = Class.forName(sClassName); | |
Annotation[] aAnnotations = classToInvestigate.getDeclaredAnnotations(); | |
for(Annotation a : aAnnotations) | |
{ | |
// Found an annotation, use a.toString() to print it out | |
} | |
} catch (ClassNotFoundException e) { | |
// Class not found! | |
} catch (Exception e) { | |
// Handle unknown exception! | |
} | |
if(classToInvestigate.isAnnotationPresent(java.lang.Deprecated.class) == true) | |
{ | |
// Class is deprecated! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment