我正在开发一个 Java 11 项目,
这是我的 build.gradle:
plugins {
id 'java'
}
//
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
implementation 'org.projectlombok:lombok:1.18.18'
implementation "io.vavr:vavr:0.10.3"
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
implementation 'systems.manifold:manifold-science:2021.1.25-SNAPSHOT'
testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
My Manifold 的扩展方法:
import manifold.ext.rt.api.Extension;
import manifold.ext.rt.api.This;
@Extension
public class MyStringEx {
public static void echo(@This String thiz) {
System.out.println(thiz);
}
}
它编译成功。但是现在,我想通过 Manifold 扩展注释向java.lang.String
类添加一个方法,我试过这个:
public class Main {
public static void main(String[] args) {
"hello".echo(); // Add your own methods to String!
}
}
但我得到错误:
java: cannot find symbol
symbol: method echo()
location: class java.lang.String