본문 바로가기
[Java] Reflection Tutorial - Generics Java, Reflection Tutorial - Generics 일반적으로 Generics 정보는 runtime 에 사라진다고 알고 있지만 꼭 그렇지만은 않다. The Generics Reflection Rule of Thumb 일반적으로 List 와 같은 녀석들은 어떤 Generic 이 쓰였는지 알기 어렵다.하지만 parameterized 된 method 나 field 를 조사해보면,어떤 generic 이 사용되었는지 알 수 있다. Generic Method Return Types Method method = TestClass.class.getMethod( "getStringList", null );Type returnType = method.getGenericReturnType(); if ( ret.. 2013. 12. 27.
[Java] Reflection Tutorial - Annotations. [Java] Reflection Tutorial - Annotations. What are Java Annotations Java5 에 소개된 기능으로, meta data 를 코드형태로 담을 수 있고, runtime 에 이 meta data 에 접근할 수 있다. pre-compiler 가 코드를 conversion 할 때 사용되기도 한다. Annotation 은 interface 형태이다. @Retention( RetentionPolicy.RUNTIME );@Target( ElementType.TYPE )public @interface TestAnnotation{public String name();public String value();} @TestAnnotation(name="variable", va.. 2013. 12. 23.
[Java] Reflection Tutorial - Accessing Private Field, Private Method Java, Reflection Tutorial - Accessing Private Field, Private Method Reflection 으로 private field, method 들에도 접근할 수 있다.private 에 대한 접근은 unit test 에서 유용하게 쓰인다. VM 에 따라서 권한이 주어져야 접근 가능한 경우도 있다. Accessing Private Fields TestClass testClass = new TestClass();Field privateField = testClass.getDeclaredField( String name );privateField.setAccessible( true );privateField.get( testClass ); setAccessible 을 .. 2013. 12. 17.
[Java] Reflection Tutorial - Getter and Setter Java, Reflection Tutorial - Getter and Setter Getter 와 Setter 의 경우 일일히 getter setter method 를 얻어와야 한다. Setter 의 경우에 return value 가 있을 수도 있다는 것을 알아야 한다. 100% 정확한 방법은 아니지만 general 한 방법의 (POJO) getter, setter 는 아래와 같은 방법으로 조회할 수 있다. public static boolean isGetter(Method method){ if(!method.getName().startsWith("get")) return false; if(method.getParameterTypes().length != 0) return false; if(void.cl.. 2013. 12. 4.
[android] NavigationDrawer Tutorial android, NavigationDrawer Tutorial Layout You should use DrawerLayout to enable your app edge activated for open drawer automatically.Otherwise you have to implement drawer open touch event by yourself. You must keep in mind that FrameLayout that is responsible for drawer has to be come last.Because android draws xml declared layout from the bottom so that the drawer will be come most upper part.. 2013. 11. 28.
[Java] Reflection Tutorial - Method Java, Reflection Tutorial - Method Obtaining Method Objects Method[] methods = aClass.getMethods(); // only public methodsMethod method = aClass.getMethod( "methodName", Class[]{ String.class} ); getMethod 함수는 NoSuchMethodException 을 throw 할 수 있음 no parameter case 는 Class[] 부분에 null 을 입력. Method Parameters and Return Types. Class[] parameterTypes = method.getParameterTypes();Class returnType = m.. 2013. 11. 28.
[PHP] 코드 재활용과 함수 작성 Tutorial PHP, 코드 재활용과 함수 작성 Tutorial =====require() 와 include() 사용하기 - require( "fileName" ) 을 사용하면require()를 호출한 자리가 해당 파일 내용으로 바뀌고 스크립트가 실행된다. - require() 로 불러들이는 파일이 로 감싸있지 않다면,html 파일 형식으로 불러들인다. - include 는 require 와 기능을 같다.다만 require 는 실패했을 경우 치명적 오류를 내지만, include 는 가벼운 오류만 내뿜는다. - require_once(), include_once()파일을 한번만 포함시킨다.library 를 포함시킬 때 같은 라이브러리를 두 번 이상 포함시키는 일을 막아준다. =====auto_prepend_file, a.. 2013. 11. 26.
[PHP] Tutorial, 객체 지향 PHP, Tutorial, 객체 지향 =====PHP 에서 클래스, 속성, 연산 만들기 class classname{ var $attribute1; function operation1( $param1 ){ }} =====생성자 __construct() 라는 이름을 가진다. =====소멸자 __destruct() 라는 이름을 가진다. =====생성 new 를 이용하여 생성한다. =====클래스 속성 사용하기 instance->attributeName 으로 접근한다. =====GET, SET 함수 __get, __set 함수를 가진다.해당 attribute 에 접근하면 자동으로 get, set 함수가 불리게 된다. =====private 와 public 으로 접근 제어하기 기본은 public. private.. 2013. 11. 15.
[Java] Reflection Tutorial - Constructor Java, Reflection Tutorial - Constructor Obtaining Constructor Objects Constructor[] constructors = aClass.getConstructors(); public Constructor 들만 가지고 온다. 만약 parameter 들을 확실히 알고 있다면, 다음과 같이 한개의 constructor 를 가져올 수 있다. Constructor constructor = aClass.getConstructor( new Class[]{ String.class} ); 만약 일치하는 constructor 가 없다면 NoSuchMethodException 이 return 된다. Constructor Parameters Class[] parameter.. 2013. 11. 15.
반응형