小编Zhe*_*lov的帖子

为什么Scala中没有"Functor"特征?

在Scala中,通用类,如Future,OptionList一切有方法mapflatMap.据我所知,他们都像Haskell中的Functors.

我只是想知道为什么Scala中没有一个名为Functor的特征(界面).

有没有人有这个想法?

haskell functional-programming scala functor

7
推荐指数
2
解决办法
718
查看次数

内容/ MacOS在4.5.2中不存在

我正在尝试将我的项目从eclipse 3.8.2升级到eclipse 4.5.2.在使用pde build构建我的项目时,我收到以下错误.\ Contents\MacOS不存在.

这部分在早期版本中运行良好.

我已将java SDK,delta pack更新为4.5.2

细节:

C:\p4root\common\build_templates\eclipse_pde\build.xml:144: The following error occurred while executing this line:
[exec] C:\eclipse4.5.2\plugins\org.eclipse.pde.build_3.9.100.v20150521-1524\scripts\productBuild\productBuild.xml:45: The following error occurred while executing this line:
[exec] C:\eclipse4.5.2\plugins\org.eclipse.pde.build_3.9.100.v20150521-1524\scripts\build.xml:129: The following error occurred while executing this line:
[exec] C:\p4root\myproject\dev\build\myproject\configuration\customTargets.xml:29: The following error occurred while executing this line:
[exec] C:\eclipse4.5.2\plugins\org.eclipse.pde.build_3.9.100.v20150521-1524\scripts\productBuild\allElements.xml:20: The following error occurred while executing this line:
[exec] C:\eclipse4.5.2\plugins\org.eclipse.pde.build_3.9.100.v20150521-1524\scripts\genericTargets.xml:195: The following error occurred while executing this line:
[exec] C:\p4root\myproject\dev\build\myproject\base\package.org.eclipse.pde.build.container.feature.all.xml:27: The following error occurred while executing this line:
[exec] …
Run Code Online (Sandbox Code Playgroud)

java eclipse

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

ProGuard是否支持Java 11?

我试图使用Proguard(6.1.0beta1),但得到了

(Unsupported version number [55.0] (maximum 54.0, Java 10)))
Run Code Online (Sandbox Code Playgroud)

是否有ProGuard的替代品,可以使用Java 11进行管理?

java proguard

7
推荐指数
2
解决办法
2025
查看次数

使类公开,但对JAR文件保持私有

有没有办法让Java类公开但只公开一个JAR文件?AKA,它不是私有包,而是公共包,但它不是公共JAR?

说我有这样的结构:

project/
  package1/
    One.java
  package2/
    Two.java
  package3/
    Three.java
Run Code Online (Sandbox Code Playgroud)

由于3 .java文件在不同的包中,我需要公开.但有没有办法让它们只对包含该项目的JAR公开?这样如果另一个项目导入JAR,它就看不到某些公共类/字段?

java maven java-platform-module-system java-11

7
推荐指数
2
解决办法
131
查看次数

Spliterator用于不可变链表

这是不可变链表的经典实现:

public abstract class List<A> implements Iterable<A> {
    private static final List NIL = new Nil();

    public abstract A head();
    public abstract List<A> tail();
    public List<A> cons(A a) { return new Cons<>(a, this); }

    public static <A> List<A> nil() { return NIL; }

    @Override
    public Iterator<A> iterator() {
        return new Iterator<A>() {
            private List<A> list = List.this;

            @Override
            public boolean hasNext() {
                return list != NIL;
            }

            @Override
            public A next() {
                A n = list.head();
                list = list.tail();
                return …
Run Code Online (Sandbox Code Playgroud)

java linked-list singly-linked-list java-8 spliterator

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

根据键列表过滤地图

我有一张如下地图:

class Person {

    Long personId;
    String name;

    /*Getters and Setters*/
}
Run Code Online (Sandbox Code Playgroud)

我填写了一张地图 Map<Long, Person> personMap = new HashMap<>();

地图的关键是personId本身.我有一个像这样的personIds列表,

List<Long> coolPeople = new ArrayList<>();

现在我想遍历地图并使用与列表中的ID相对应的键获取所有值coolPeople,然后将其存储在List中.

如何在Java 8中实现最佳效果?

java collections java-8 java-stream

6
推荐指数
2
解决办法
6662
查看次数

无法使用Java 9启动solr

我无法在Java 9上启动solr,导致跟随错误.

[shahid@host172 logs]$ tail -20 solr-8983-console.log 
Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Java HotSpot(TM) 64-Bit Server VM warning: Option UseParNewGC was deprecated in version 9.0 and will likely be removed in a future release.
Unrecognized VM option 'PrintHeapAtGC'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Run Code Online (Sandbox Code Playgroud)

java linux solr java-9

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

使用jigsaw模块使用jdk9运行spring boot

这个应用程序出了什么问题.我认为classpath jar和模块jar的混合是有效的.对于没有明确模块信息的所有罐子成为自动模块?当我删除我的module-info.java时,它可以工作.因为IDEA在这种情况下使用了类路径.

Java(TM)SE运行时环境(版本9 + 176)

IntelliJ IDEA 2017.1.4

module-info.java

module test {
    requires spring.boot.autoconfigure;
    requires spring.boot;
}
Run Code Online (Sandbox Code Playgroud)

App.java

package com.foo.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.foo.test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.M2</version>
    </parent>

    <name>test</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.9</maven.compiler.source>
        <maven.compiler.target>1.9</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url> …
Run Code Online (Sandbox Code Playgroud)

java spring java-platform-module-system java-9

6
推荐指数
2
解决办法
2880
查看次数

如何在Java 9上运行jol?

我正在尝试使用jolJava 9 运行程序,但没有运气.

我有以下依赖pom.xml:

<dependency>
    <groupId>org.openjdk.jol</groupId>
    <artifactId>jol-core</artifactId>
    <version>0.9</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

该计划很简单:

package org.example;

import org.openjdk.jol.vm.VM;

public class Example {
    public static void main(String[] args) throws Throwable {
        System.out.println(VM.current().details());
    }
}
Run Code Online (Sandbox Code Playgroud)

模块描述符:

module java9 {
    requires jol.core;
}
Run Code Online (Sandbox Code Playgroud)

当我从IDEA运行程序时,我看到以下输出:

# WARNING: Unable to get Instrumentation. Dynamic Attach failed.
You may add this JAR as -javaagent manually, or supply -Djdk.attach.allowAttachSelf
Run Code Online (Sandbox Code Playgroud)

-Djdk.attach.allowAttachSelf=true在IDEA中添加了VM参数,但它没有帮助(仍然是相同的输出).

PS我可以从类路径成功运行程序.尽管如此,如何从模块路径运行它仍然很有趣.

java jol java-9

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

为什么模块路径上的模块需要 --add-modules ?

一个例子:由于 JavaFx 从 JDK 中删除,JavaFx SDK 现在作为一组模块化 jar 分发。要编译 JavaFx 应用程序,当然必须将它们放在模块路径中:

javac -p /path/to/jars/ App.java
Run Code Online (Sandbox Code Playgroud)

然而,这还不够。尝试编译会导致很多类似的错误

sample/App.java:3: error: package javafx.application is not visible
import javafx.application.Application;
             ^
  (package javafx.application is declared in module javafx.graphics, which is not in the module graph)
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我们可以使用 --add-modules 添加 javafx.graphics:

javac -p /path/to/jars/ --add-modules javafx.graphics App.java
Run Code Online (Sandbox Code Playgroud)

但是,如果我们将 module-info.java(仅包含module ui {})添加到项目中,则没有问题。

为什么模块路径上的模块对命名模块可见,但对未命名模块不可见?

java java-platform-module-system java-9 java-module java-11

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