我正在玩未来的Java 8版本,即JDK 1.8.
我发现你很容易做到
interface Foo { int method(); }
Run Code Online (Sandbox Code Playgroud)
并使用它
Foo foo = () -> 3;
System.out.println("foo.method(); = " + foo.method());
Run Code Online (Sandbox Code Playgroud)
只打印3.
我还发现有一个java.util.function.Function接口以更通用的方式执行此操作.但是这段代码不会编译
Function times3 = (Integer triple) -> 3 * triple;
Integer twelve = times3.map(4);
Run Code Online (Sandbox Code Playgroud)
似乎我首先要做的事情
interface IntIntFunction extends Function<Integer, Integer> {}
IntIntFunction times3 = (Integer triple) -> 3 * triple;
Integer twelve = times3.map(4);
Run Code Online (Sandbox Code Playgroud)
所以我想知道是否有另一种方法可以避免IntIntFunction步骤?
我使用 Spring Boot 2.1.6.RELEASE 在 Spring 中创建了一个简单的方面。它基本上记录了在方法上花费的总时间。
@Aspect
@Component
public class TimeLoggerAspect {
private static final Logger log = LoggerFactory.getLogger(TimeLoggerAspect.class);
@Around("@annotation(demo.TimeLogger)")
public Object methodTimeLogger(ProceedingJoinPoint joinPoint)
throws Throwable {
long startTime = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long totalTime = System.currentTimeMillis() - startTime;
log.info("Method " + joinPoint.getSignature() + ": " + totalTime + "ms");
return proceed;
}
}
Run Code Online (Sandbox Code Playgroud)
方面由TimeLogger注释触发
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TimeLogger {
}
Run Code Online (Sandbox Code Playgroud)
并在这样的组件中使用
@Component
public class DemoComponent {
@TimeLogger
public void sayHello() {
System.out.println("hello");
} …Run Code Online (Sandbox Code Playgroud) OWL是否可能对语言属性具有最大基数限制,这将限制每种语言的基数。
例如,我只希望dct:title每种语言最多一种。所以,
:demo dct:title "Demo"@en, "Demo"@nl.
Run Code Online (Sandbox Code Playgroud)
可以,但是
:bad_demo dct:title "Bad demo"@en, "Wrong demo"@en.
Run Code Online (Sandbox Code Playgroud)
会给一个错误?