1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import java.lang.reflect.Method; 18 19 /** 20 * Test reflection on old-style inner classes. 21 */ 22 public class Main { 23 private static Runnable theRunnable = new Runnable() { 24 public void run() { } 25 }; 26 27 private static Runnable create() { 28 return new Runnable() { 29 public void run() { } 30 }; 31 } 32 33 private static String nameOf(Class clazz) { 34 return (clazz == null) ? "(null)" : clazz.getName(); 35 } 36 37 private static String nameOf(Method meth) { 38 return (meth == null) ? "(null)" : meth.toString(); 39 } 40 41 private static void infoFor(Class clazz) { 42 System.out.println("Class: " + nameOf(clazz) + "\n" + 43 " getDeclaringClass(): " + 44 nameOf(clazz.getDeclaringClass()) + "\n" + 45 " getEnclosingClass(): " + 46 nameOf(clazz.getEnclosingClass()) + "\n" + 47 " getEnclosingMethod(): " + 48 nameOf(clazz.getEnclosingMethod())); 49 } 50 51 public static void main(String args[]) { 52 infoFor(theRunnable.getClass()); 53 infoFor(create().getClass()); 54 } 55 } 56