137602aa68202073c3738ae710693a5b73fb2610aVladimir Marko/*
237602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * Copyright (C) 2018 The Android Open Source Project
337602aa68202073c3738ae710693a5b73fb2610aVladimir Marko *
437602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * Licensed under the Apache License, Version 2.0 (the "License");
537602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * you may not use this file except in compliance with the License.
637602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * You may obtain a copy of the License at
737602aa68202073c3738ae710693a5b73fb2610aVladimir Marko *
837602aa68202073c3738ae710693a5b73fb2610aVladimir Marko *      http://www.apache.org/licenses/LICENSE-2.0
937602aa68202073c3738ae710693a5b73fb2610aVladimir Marko *
1037602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * Unless required by applicable law or agreed to in writing, software
1137602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * distributed under the License is distributed on an "AS IS" BASIS,
1237602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1337602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * See the License for the specific language governing permissions and
1437602aa68202073c3738ae710693a5b73fb2610aVladimir Marko * limitations under the License.
1537602aa68202073c3738ae710693a5b73fb2610aVladimir Marko */
1637602aa68202073c3738ae710693a5b73fb2610aVladimir Marko
1737602aa68202073c3738ae710693a5b73fb2610aVladimir Markoimport java.lang.reflect.InvocationHandler;
1837602aa68202073c3738ae710693a5b73fb2610aVladimir Markoimport java.lang.reflect.Method;
1937602aa68202073c3738ae710693a5b73fb2610aVladimir Markoimport java.lang.reflect.Proxy;
2037602aa68202073c3738ae710693a5b73fb2610aVladimir Marko
2137602aa68202073c3738ae710693a5b73fb2610aVladimir Markopublic class Main {
2237602aa68202073c3738ae710693a5b73fb2610aVladimir Marko    public static void main(String[] args) throws Exception {
2337602aa68202073c3738ae710693a5b73fb2610aVladimir Marko        Interface i = (Interface) Proxy.newProxyInstance(Main.class.getClassLoader(),
2437602aa68202073c3738ae710693a5b73fb2610aVladimir Marko                                                         new Class<?>[] { Interface.class },
2537602aa68202073c3738ae710693a5b73fb2610aVladimir Marko                                                         new Handler());
2637602aa68202073c3738ae710693a5b73fb2610aVladimir Marko        i.foo();
2737602aa68202073c3738ae710693a5b73fb2610aVladimir Marko    }
2837602aa68202073c3738ae710693a5b73fb2610aVladimir Marko}
2937602aa68202073c3738ae710693a5b73fb2610aVladimir Marko
3037602aa68202073c3738ae710693a5b73fb2610aVladimir Markointerface Interface {
3137602aa68202073c3738ae710693a5b73fb2610aVladimir Marko    void foo();
3237602aa68202073c3738ae710693a5b73fb2610aVladimir Marko}
3337602aa68202073c3738ae710693a5b73fb2610aVladimir Marko
3437602aa68202073c3738ae710693a5b73fb2610aVladimir Markoclass Handler implements InvocationHandler {
3537602aa68202073c3738ae710693a5b73fb2610aVladimir Marko    public Object invoke(Object proxy, Method method, Object[] args) {
3637602aa68202073c3738ae710693a5b73fb2610aVladimir Marko        System.out.println("Method: " + method);
3737602aa68202073c3738ae710693a5b73fb2610aVladimir Marko        return null;
3837602aa68202073c3738ae710693a5b73fb2610aVladimir Marko    }
3937602aa68202073c3738ae710693a5b73fb2610aVladimir Marko}
40