小编Nat*_*Cox的帖子

Java 8中的Lambdas和泛型

我正在玩未来的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步骤?

java lambda java-8

15
推荐指数
1
解决办法
4793
查看次数

如何使用 SpringBootTest 测试方面?

我使用 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)

java aop aspectj spring-boot

8
推荐指数
4
解决办法
7205
查看次数

每种语言的OWL rdfs:langString maxCardinality

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)

会给一个错误?

rdf semantic-web owl ontology rdfs

1
推荐指数
1
解决办法
60
查看次数

标签 统计

java ×2

aop ×1

aspectj ×1

java-8 ×1

lambda ×1

ontology ×1

owl ×1

rdf ×1

rdfs ×1

semantic-web ×1

spring-boot ×1