Christoffer Quist Adamsen | 0be95fb | 2018-07-06 10:45:56 +0200 | [diff] [blame] | 1 | // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | package classmerging; |
| 6 | |
| 7 | public class FieldCollisionTest { |
| 8 | |
| 9 | private static final B SENTINEL_A = new B("A"); |
| 10 | private static final B SENTINEL_B = new B("B"); |
| 11 | |
| 12 | public static void main(String[] args) { |
| 13 | B obj = new B(); |
| 14 | System.out.println(obj.toString()); |
| 15 | } |
| 16 | |
| 17 | // Will be merged into B. |
| 18 | public static class A { |
| 19 | |
| 20 | // After class merging, this field will have the same name and type as the field B.obj, |
| 21 | // unless we handle the collision. |
| 22 | protected final A obj = SENTINEL_A; |
| 23 | } |
| 24 | |
| 25 | public static class B extends A { |
| 26 | |
| 27 | protected final String message; |
| 28 | protected final B obj = SENTINEL_B; |
| 29 | |
| 30 | public B() { |
| 31 | this(null); |
| 32 | } |
| 33 | |
| 34 | public B(String message) { |
| 35 | this.message = message; |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public String toString() { |
| 40 | return obj.message + System.lineSeparator() + ((B) super.obj).message; |
| 41 | } |
| 42 | } |
| 43 | } |