Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

29
LINES

< > BotCompany Repo | #1029851 // using call() on proxy objects test (OK)

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (2149L/12K).

!7

sinterface MyInterface {
  S hello();
}

sclass MyImpl {
  S hello() { ret "hello"; }
  S hello2() { ret "hello2"; }
}

cprint {
  start-thread {
    MyInterface proxy = proxy(new MyImpl, MyInterface);
    assertEqualsVerbose("hello", proxy.hello());
    
    // reflectively calling a method on a proxy is OK
    // - if the method is in the interface
    assertEqualsVerbose("hello", call(proxy, "hello"));
    
    // Random method calls, OTOH, are not forwarded to the
    // proxied object.
    assertFailsVerbose(r { call(proxy, "hello2") });
    
    // But of course we can extract the proxied object and call its methods.
    O proxied = getProxiedObject(proxy);
    assertEqualsVerbose("hello2", call(proxied, "hello2"));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1029851
Snippet name: using call() on proxy objects test (OK)
Eternal ID of this version: #1029851/6
Text MD5: 41d85fb25ec550beb2fe23758b8b572e
Transpilation MD5: 17d1fb94bacf3ea08593061cbe37c6a3
Author: stefan
Category: javax / web
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-23 11:27:09
Source code size: 771 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 186 / 291
Version history: 5 change(s)
Referenced in: [show references]