当前位置: 首页 > 工具软件 > Manifold > 使用案例 >

manifold.ext.rt manifold @Extension

蒯华彩
2023-12-01

在使用 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 select 11 for both Project JDK and Project 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");
  }


}
 类似资料: