Skip to content

Instantly share code, notes, and snippets.

@motlin
Last active October 12, 2022 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motlin/b3a44089acda2fbba2580214f87f803a to your computer and use it in GitHub Desktop.
Save motlin/b3a44089acda2fbba2580214f87f803a to your computer and use it in GitHub Desktop.
Java for testing syntax highlighting
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