Last active
October 12, 2022 01:57
-
-
Save motlin/b3a44089acda2fbba2580214f87f803a to your computer and use it in GitHub Desktop.
Java for testing syntax highlighting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class Main | |
{ | |
public static void main(String[] args) | |
{ | |
MyInterface myInterface = new ConcreteClass(); | |
ConcreteClass concreteClass = new ConcreteClass(); | |
AbstractClass abstractClass = new ConcreteClass(); | |
myInterface.abstractMethod(); | |
myInterface.defaultMethod(); | |
var strings = Arrays.asList( | |
Constants.STATIC_FINAL, | |
Constants.STATIC, | |
Constants.staticMethod(), | |
concreteClass.instanceFinal, | |
concreteClass.instance, | |
concreteClass.abstractMethod()); | |
int effectivelyFinal = 1; | |
int reassigned = 2; | |
reassigned = 3; | |
var string = "string"; | |
var number = 123.456; | |
String error = 1; | |
String warning = "" + concreteClass.toString(); | |
int weakWarning = 1000000; | |
} | |
public interface MyInterface | |
{ | |
String abstractMethod(); | |
default String defaultMethod() | |
{ | |
return this.toString(); | |
} | |
} | |
public abstract static class AbstractClass | |
implements MyInterface | |
{ | |
} | |
public static class ConcreteClass | |
extends AbstractClass | |
{ | |
public final String instanceFinal = "instance"; | |
public String instance = "instance"; | |
public void setInstance(String instance) | |
{ | |
this.instance = instance; | |
} | |
@Override | |
public String abstractMethod() | |
{ | |
return this.defaultMethod(); | |
} | |
} | |
public static class Constants | |
{ | |
public static final String STATIC_FINAL = "constant"; | |
public static String STATIC = "non-constant"; | |
public static String staticMethod() | |
{ | |
return ""; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment