在使用 manifold 的时候需要以下步骤:
If you simply want to experiment with Manifold, this project will help get you started.
git clone https://github.com/manifold-systems/manifold-sample-project.git
- Open IntelliJ IDEA
- Install the Manifold plugin from within IntelliJ:
Settings | Plugins | Marketplace
- Restart IntelliJ to use the plugin
- Open the project you just cloned (open the root directory or the pom.xml file)
- Add the Java 11 JDK:
File | Project Structure | SDKs | + | path-to-your-Jdk11
- Set the project JDK and language level:
File | Project Structure | Project
select11
for bothProject JDK
andProject language level
- Build the project
- Examine the
abc/RunMe.java
file
1. map 扩展
package manifoldsampleproject.extensions.java.util.Map;
import manifold.ext.rt.api.Extension;
import manifold.ext.rt.api.This;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@Extension
public class MyMapExtension {
public static <K, V> boolean containsKeys(@This Map<K, V> thiz, Collection<K> keys) {
return thiz.keySet().containsAll(keys);
}
public static class Entry {
public static <K, V> String hiFromEntry(@This Map.Entry<K, V> thiz) {
return "hiFromEntry";
}
}
/**
* 我的put
* @param thiz
* @param k
* @param v
* @param <K>
* @param <V>
* @return
*/
public static <K, V> Map<K, V> myPut(@This Map<K,V> thiz,K k,V v){
thiz.put(k,v);
return thiz;
}
}
2. 字符串扩展
package manifoldsampleproject.extensions.java.lang.String;
import manifold.ext.rt.api.Extension;
import manifold.ext.rt.api.This;
import java.lang.String;
@Extension
public class MyStringExt {
public static void echo( @This String thiz) {
System.out.println(thiz);
}
public static void print( @This String thiz) {
System.out.println(thiz+"qqq");
}
}