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

27
LINES

< > BotCompany Repo | #1030769 // swappable + inheritance 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 (2124L/11K).

1  
!7
2  
3  
cprint {
4  
  class A {
5  
    swappable S x() { ret "a"; }
6  
  }
7  
  
8  
  class B extends A {
9  
    swappable S x_inner() { ret super.x_base(); }
10  
    S x_base() { ret "b" + x_inner(); }
11  
  }
12  
  
13  
  start-thread {
14  
    assertEqualsVerbose("a", new A().x());
15  
    assertEqualsVerbose("ba", new B().x());
16  
    
17  
    // override the whole x() method
18  
    new B c;
19  
    c.x = () -> "c";
20  
    assertEqualsVerbose("c", c.x());
21  
    
22  
    // override the A.x() method while keeping B's added logic
23  
    c = new B;
24  
    c.x_inner = () -> "c";
25  
    assertEqualsVerbose("bc", c.x());
26  
  }
27  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1030769
Snippet name: swappable + inheritance test [OK]
Eternal ID of this version: #1030769/11
Text MD5: 36a8a2218004bb5e92c74aadbbccbc0d
Transpilation MD5: 01ab8f3ce60cb9c7c2351d74ac9e5d31
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-19 16:13:06
Source code size: 580 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 173 / 263
Version history: 10 change(s)
Referenced in: [show references]