我想合并两个列表:
import scalaz.syntax.align._
import scalaz.std.list._
import scalaz.std.anyVal._
List(1, 2, 3).merge(List(4, 5, 6, 7)) // Evaluates to List(5, 7, 9, 7)
Run Code Online (Sandbox Code Playgroud)
这隐含地使用标准加法monoid.如果我想使用乘法幺半群怎么办?在Scalaz中这样做的惯用方法是什么?
我想org.eclipse.swt为片段创建一个扩展.我创建了一个swt.extension包含以下MANIFEST.MF 的包:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Extension
Bundle-SymbolicName: swt.extension
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.swt;bundle-version="3.102.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Run Code Online (Sandbox Code Playgroud)
另外,我创建了一个从SWT扩展接口的接口:
public interface IExtendedStyleTextContent extends org.eclipse.swt.custom.StyledTextContent {
}
Run Code Online (Sandbox Code Playgroud)
当我使用tycho(mvn clean install)构建项目时,会发生以下错误:
1. ERROR in C:\<path>\tycho-fragment-to-fragment-dependency\swt.extension\src\org\example\tycho_example\IExtendedStyleTextContent.java (at line 3)
public interface IExtendedStyleTextContent extends org.eclipse.swt.custom.StyledTextContent {
^^^^^^^^^^^
org.eclipse cannot be resolved to a type
Run Code Online (Sandbox Code Playgroud)
似乎tycho只解析了org.eclipse.swt jar.这是一个主机包,它不包含任何类.实际的实现是在org.eclipse.swt.win32.win32.x86_64片段包中.当tycho-compiler-plugin编译项目时,看起来这个bundle不在classpath上.
这是第谷的错误吗?他们有任何变通方法吗?
我把所有资源放在GitHub上:https://github.com/orionll/tycho-fragment-to-fragment-dependency
我使用maven 3.1.0
我有以下功能:
f :: (Int -> Int) -> Int
f = undefined
Run Code Online (Sandbox Code Playgroud)
现在,我想打电话f与5(这是不正确的):
f 5
Run Code Online (Sandbox Code Playgroud)
显然,这不应该编译,因为5不是从功能Int到Int.所以我希望有一个错误信息Couldn't match expected type Int -> Int with Int.
但相反,我得到:
No instance for (Num (Int -> Int)) arising from the literal `5'
In the first argument of `f', namely `5'
In the expression: f 5
In an equation for `it': it = f 5
Run Code Online (Sandbox Code Playgroud)
为什么Num会出现在这里?
很抱歉有新手问题,但我真的不明白重载值:
GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
Prelude> let x = 1
Prelude> let y = 2
Run Code Online (Sandbox Code Playgroud)
无论x和y有型Num a => a.但是没有(/)定义Num!那么为什么表达式x / y检查呢?
Prelude> x / y
0.5
Run Code Online (Sandbox Code Playgroud)
(/)在课堂上定义Fractional.有一些隐式转换Num到Fractional?
UPD:
因此,正如预期的那样,我得到的答案是人们声称这x / y a是专门的Fractional a => a.
我创建了自己的数字层次结构:
data MyInt = MyInt Integer deriving Show
data MyDouble = MyDouble Double deriving Show
class MyNum a …Run Code Online (Sandbox Code Playgroud) {-# LANGUAGE DeriveDataTypeable #-}
import Control.Exception
import Data.Typeable
data MyException = MyException String deriving (Show, Typeable)
instance Exception MyException
myExToString :: MyException -> String
myExToString (MyException msg) = msg
t :: ()
t = throw $ MyException "Msg"
main = catch (return t) (\e -> putStrLn $ myExToString e)
Run Code Online (Sandbox Code Playgroud)
为什么我的程序不打印"Msg"?
更新:
我更改了代码:
io :: IO ()
io = catch (return t) (\e -> putStrLn $ myExToString e)
main = io >>= print
Run Code Online (Sandbox Code Playgroud)
但我的代码仍然没有捕获MyException?为什么?
如果我理解正确,Java 10的二进制形式与Java 9完全相同,那么它不会产生任何问题.
我的假设是否正确?
我在JDK 9上使用Ignite遇到麻烦。我有以下最小测试用例:
package no.ovstetun.ignite;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.junit.Test;
public class FailingIgniteTest {
@Test
public void failingIgnite() {
TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
}
}
Run Code Online (Sandbox Code Playgroud)
此代码示例失败,并带有以下stacktrace:
java.lang.ExceptionInInitializerError
at org.apache.ignite.internal.util.IgniteUtils.<clinit>(IgniteUtils.java:769)
at org.apache.ignite.spi.IgniteSpiAdapter.<init>(IgniteSpiAdapter.java:119)
at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.<init>(TcpDiscoverySpi.java:231)
at no.nrk.mdb.common.infrastructure.ignite.IgniteConfigurationTest.failingIgnite(IgniteConfigurationTest.java:10)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused …Run Code Online (Sandbox Code Playgroud) 我正在遵循本教程,该教程尝试通过构建最小的 JVM 来最小化 JVM 内存占用。
当我跑步时,jdeps -s myjar.jar我得到:
myjar.jar -> java.base
myjar.jar -> java.logging
myjar.jar -> not found
Run Code Online (Sandbox Code Playgroud)
在教程中,他通过运行另一个命令解决了这个问题。
jdeps -cp 'lib/*' -recursive -s myjar.jar
Run Code Online (Sandbox Code Playgroud)
我尝试过这个,但得到了相同的结果。
如何正确运行呢?
我正在尝试找到一种解决方法,使 Nashorn 与 1.8 以上的每个 Java 版本兼容,正如我之前提出的另一个问题中所述。
我目前正在尝试捕获UnsupportedClassVersionError系统是否能够运行独立的 Java 15 Nashorn,如下所示(Kotlin 代码):
scriptEngine = try {
// Java >= 15
org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine
} catch(e: UnsupportedClassVersionError) {
// Java < 15
@Suppress("DEPRECATION")
jdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine
}
Run Code Online (Sandbox Code Playgroud)
但看起来错误没有被捕获。堆栈跟踪如下:
java.lang.UnsupportedClassVersionError: org/openjdk/nashorn/api/linker/NashornLinkerExporter has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 55.0
Run Code Online (Sandbox Code Playgroud)
我还尝试捕获NoClassDefFoundError反转之前的 try/catch (加载 Java < 15 Nashorn,如果不存在则加载独立的),但错误是相同的。 …
我们正在迁移旧代码,实际上相当旧的代码到 Java 11。我在编译其中一个类时遇到问题。示例代码是:
package XXXX;
import java.lang.ref.*;
import sun.security.action.*;
import java.security.*;
import java.io.*;
class Converters
{
private static Object lock;
private static String converterPackageName;
private static String defaultEncoding;
public static final int BYTE_TO_CHAR = 0;
public static final int CHAR_TO_BYTE = 1;
private static final String[] converterPrefix;
private static SoftReference[] classCache;
static /* synthetic */ Class class$sun$io$Converters;
private static String getConverterPackageName() {
final String converterPackageName = Converters.converterPackageName;
if (converterPackageName != null) {
return converterPackageName;
}
String converterPackageName2 = AccessController.doPrivileged((PrivilegedAction<String>)new GetPropertyAction("file.encoding.pkg")); …Run Code Online (Sandbox Code Playgroud)