小编Nik*_*hil的帖子

Java 8 Lambda将Number [] []转换为double [] []

Number[][] intArray = new Integer[][]{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
double[][] doubleArray = Arrays.stream(intArray)
                            .forEach(pArray -> Arrays.stream(pArray)
                                                .mapToDouble(d ->d.doubleValue())
                                                .toArray())
                            .toArray();
Run Code Online (Sandbox Code Playgroud)

我想将Number [] []转换为double [] [].上面的lambda不起作用,外部的toArray不能编译.

Arrays.stream(intArray):返回Integer []
forEach 的流 :对于每个Integer [],创建一个Integers流,将每个Integer转换为double并返回double [].
for each创建double [],我认为外部toArray将返回此double的数组[]
我怎样才能使它 工作?

java arrays lambda 2d java-8

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

带有 google_checks 和 4 个空格 indentSize 的 Maven Checkstyle 插件

我正在寻找配置 google_checks 以4 spaces在 Maven Checkstyle 插件中使用的方法。我将indentSize配置参数设置为4,但是不起作用。有配置选项来设置这个吗?我不想拥有自己的版本,google_checks.xml只是缩进 4 个空格。

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>3.1.1</version>
        <dependencies>
          <dependency>
            <artifactId>checkstyle</artifactId>
            <groupId>com.puppycrawl.tools</groupId>
            <version>8.36.1</version>
          </dependency>
        </dependencies>
        <configuration>
          <configLocation>google_checks.xml</configLocation>
          <indentSize>4</indentSize>
          <failsOnError>true</failsOnError>
          <consoleOutput>true</consoleOutput>
          <includeTestSourceDirectory>true</includeTestSourceDirectory>
        </configuration>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
Run Code Online (Sandbox Code Playgroud)

更新:似乎没有办法有一个与maven-checkstyle-plugin,Checkstyle with google_checks和兼容的单一格式Intellij with google_java_format。有人能够实现这一目标吗?

checkstyle maven maven-checkstyle-plugin google-java-format

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

Spring Boot Zuul hatoas REST 响应在资源中有直接服务链接

我有 Zuul + Eureka + Spring Boot Service Endpoint + Hateoas 响应配置。当我通过 Zuul Gateway 访问服务时,响应中的资源链接是到服务端点的直接链接,它们不应该是网关链接吗?我在这里缺少什么?

网关端点:http://localhost:8762/catalog/products/10001 直接服务端点:http://localhost:8100/products/10001

Zuul 的 application.properties

spring.application.name=zuul-server
eureka.client.service-url.default-zone=http://localhost:8761/eureka/

# Map paths to services
zuul.routes.catalog-service=/catalog/**
zuul.addProxyHeaders=true
Run Code Online (Sandbox Code Playgroud)

网关端点的实际响应:http://localhost:8762/catalog/products/10001

{
  "title" : "The Title",
  "description" : "The Description",
  "brand" : "SOME BRAND",
  "price" : 100,
  "color" : "Black",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8100/products/10001"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

预期响应应在 href 中包含网关 URL

{
  "title" : "The Title",
  "description" : "The Description",
  "brand" : "SOME …
Run Code Online (Sandbox Code Playgroud)

spring spring-hateoas spring-boot netflix-eureka netflix-zuul

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