我有一个方法返回一个基类的集合:
import java.util.*;
class Base { }
class Derived extends Base { }
Collection<Base> getCollection()
{
return Arrays.asList(new Derived(),
new Derived());
}
Run Code Online (Sandbox Code Playgroud)
这无法编译,因为Arrays.asList(List<Derived>)的返回类型与方法(Collection<Base>)的返回类型不匹配.我理解为什么会发生这种情况:由于泛型类型不同,这两个类与继承无关.
有许多方法可以修复编译器错误,将方法的返回类型更改为不使用Arrays.asList将其中一个派生对象转换为Base.
有没有办法告诉编译器在解析Arrays.asList调用的泛型类型时使用不同但兼容的类型?(我一直在尝试使用这种模式并遇到这个问题,所以如果有办法让它工作,我想知道它.)
我以为你可以做点什么
Collection<Base> getCollection()
{
return Arrays.asList<Base>(new Derived(),
new Derived());
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它(java 6)时,编译器抱怨它在逗号处期望')'.
当我将shell脚本(foo.sh)添加到subversion时,默认设置为svn:mime-typeto application/x-shellscript.由于这不是从一开始text/,diff和blame基本上忽略了该文件.我查看了正式的文本mime-types列表,但没有看到任何看起来像shell脚本的东西.
是否有很好的价值来设置它?
按照下面的建议,我将mime-type设置为text/x-shellscript.但是,责备仍然认为它是一个二进制文件.
$ svn blame file.sh
Skipping binary file: 'file.sh'
$ svn proplist file.sh
Properties on 'file.sh':
svn:executable
svn:mime-type
$ svn propget svn:mime-type file.sh
text/x-shellscript
Run Code Online (Sandbox Code Playgroud)
还有什么我需要做的来说服颠覆它是一个文本文件吗?
我正在尝试使用JMX访问在docker容器内运行的应用程序.
这与此问题类似,当docker镜像内的端口映射到图像外部的相同端口时,该解决方案可以正常工作.但是,我有时想将端口映射到不同的端口.
我在托管应用程序中设置这些属性.
-Dcom.sun.management.jmxremote.port=9832
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.rmi.port=9832
-Djava.rmi.server.hostname=192.168.99.100
-Djava.rmi.server.logCalls=true
Run Code Online (Sandbox Code Playgroud)
当docker容器将端口9832映射到9832时,这可以正常工作.我可以通过JConsole或我们自己的应用程序进行连接.如果相反端口映射到另一个端口,那么我无法从JConsole或我们的应用程序访问该应用程序.
我怀疑一个或两个端口号需要是外部端口(就像java.rmi.server.hostname外部地址,而不是内部地址).但是,它失败了所有四种端口号组合.
其中两个组合不会从服务器生成日志输出.一个(我忘了哪个)产生这个输出:
Feb 09, 2016 10:35:54 PM org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl start
INFO: AMQ221001: Apache ActiveMQ Artemis Message Broker version 1.1.0 [nodeID=7a6e038e-cf7d-11e5-b566-31dc437b2d1a]
HTTP Server started at http://0.0.0.0:8161
Feb 09, 2016 10:36:06 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(1)-192.168.99.1: [192.168.99.1: sun.rmi.transport.DGCImpl[0:0:0, 2]: java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease)]
Feb 09, 2016 10:36:08 PM sun.rmi.transport.Transport serviceCall
FINE: RMI TCP Connection(1)-192.168.99.1: [192.168.99.1] exception:
java.rmi.NoSuchObjectException: no such object in table
at sun.rmi.transport.Transport.serviceCall(Transport.java:177)
at …Run Code Online (Sandbox Code Playgroud) 我正在Mypy v0.910跑步pre-commit。它抱怨python-dateutil没有类型存根。但是,即使安装了存根后,我仍然遇到相同的错误。
我的预提交配置是
default_language_version:
python: python3
repos:
<other hooks>
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
hooks:
- id: mypy
args:
- --install-types
additional_dependencies: [tokenize-rt==3.2.0]
Run Code Online (Sandbox Code Playgroud)
当我尝试提交时,它抱怨存根不存在,然后无法安装它们。
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
coordinator/policy.py:5: error: Library stubs not installed for "dateutil.parser" (or incompatible with Python 3.7)
coordinator/policy.py:5: note: Hint: "python3 -m pip install types-python-dateutil"
coordinator/policy.py:5: note: (or run "mypy --install-types" to install all missing stub packages)
tests/test_policy.py:6: error: Cannot find implementation or library stub …Run Code Online (Sandbox Code Playgroud) 我正在使用cargo,maturin和pytest来构建一个混合的 Python/Rust 项目。在开发过程中,我经常循环使用命令:
$ cargo test -p mypkg --release
$ maturin develop --release
$ python -m pytest --failed-first my_pkg
Run Code Online (Sandbox Code Playgroud)
看起来,cargo 和 maturin 正在编译依赖项,而没有理由这样做。经过一些实验,我发现如果我运行
cargo ...maturin ...cargo ...maturin ...即使我没有手动更改任何源文件,第二次运行cargo和也会重新编译依赖项。maturin
我没有一个小例子来重现这个问题,所以我尝试用完整的系统来调试它。为此,我想知道 Cargo 和/或 Maturin 认为哪些文件已经过时。一旦我知道了这一点,完整的解决方案可能就会显而易见。
但是,似乎没有我可以传递的标志来向我提供该信息。 cargo -vv test ...产生大量关于正在编译的内容和方式的输出,但不包括原因。 maturin甚至似乎没有-v可用的标志。
我发现了cargo-outdated,但这似乎与依赖版本有关。
我有两个 Rust 包,每个包都有 5-10 个直接依赖项和大约 100 个总依赖项。
如何找出哪些文件导致cargo/maturin重建依赖关系?
我正在尝试从输入映射构建映射,但是编译器无法证明2元素元组是2元素元组。
码
class Element[T] extends AnyRef { }
class Sample
{
def makeList(x:Int): Element[_] = {
x match {
case 1 => new Element[Boolean]
case 2 => new Element[(Boolean, Boolean)]
}
}
val input = Map(1 -> "one",2 -> "two")
val output = input.map(e => e._1 -> makeList(e._1)).toMap
}
Run Code Online (Sandbox Code Playgroud)
sbt编译
sbt:root> ~compile
[info] Compiling 1 Scala source to /Users/tda0106/test/scala/target/scala-2.12/classes ...
[error] /Users/tda0106/test/scala/src/main/scala/Test.scala:14:57: Cannot prove that (Int, Element[_$1]) forSome { type _$1 } <:< (T, U).
[error] val output = input.map(e …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试单元测试中是否记录了警告。看来以下测试应该失败:
import logging
import unittest
LOG_FORMAT = '%(levelname)-10s %(asctime)s: %(message)s'
def set_up_logger(app_name, level=logging.INFO, file="test.log"):
formatter = logging.Formatter(LOG_FORMAT)
log = logging.getLogger(app_name)
# The next line lets the test pass
log.setLevel(level)
return log
logger = set_up_logger(__name__)
class TestLogging(unittest.TestCase):
def test_logging(self):
with self.assertLogs(level=logging.WARNING):
logger.info('foo')
Run Code Online (Sandbox Code Playgroud)
然而,它通过了 python 3.8.5。
如果我删除该log.setLevel(level)行,测试就会失败,正如预期的那样。如果我将该logger.info行替换为pass,那么测试也会按预期失败。
为什么在记录器上设置级别会让测试错误地通过?
我已经设置了一个 docker 运行程序,我想在其中运行存储在本地存储库上的映像。我的 /etc/gitlab-runner/config.toml 是
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Docker runner"
url = "https://gitlab.str.corp/"
token = "*secret*"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "gitlab.example.com:4443/docker:19.03.1-dind"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/certs/client", "/cache"]
shm_size = 0
Run Code Online (Sandbox Code Playgroud)
当我提交作业时,它在运行器上启动,但无法拉取图像:
Running with gitlab-runner 13.4.0 (4e1f20da)
on Docker runner abcde123
Preparing the "docker" executor
Using Docker executor with image gitlab.example.com:4443/docker:19.03.8-git …Run Code Online (Sandbox Code Playgroud) scala Future类有几种基于函数式编程的方法。从Java调用时,似乎很自然地使用Java 8中的lambda。
但是,当我尝试实际使用它时,遇到了一些问题。以下代码无法编译
someScalaFuture.map(val -> Math.sqrt(val)).
map(val -> val + 3);
Run Code Online (Sandbox Code Playgroud)
因为map会将an ExecutionContext作为隐式参数。在Scala中,您可以(通常)忽略它,但是需要在Java中显式传递它。
someScalaFuture.map(val -> Math.sqrt(val),
ec).
map(val -> val + 3,
ec);
Run Code Online (Sandbox Code Playgroud)
失败并显示以下错误:
error: method map in interface Future<T> cannot be applied to given types;
[ERROR] val),ExecutionContextExecutor
reason: cannot infer type-variable(s) S
(argument mismatch; Function1 is not a functional interface
multiple non-overriding abstract methods found in interface Function1)
where S,T are type-variables:
S extends Object declared in method <S>map(Function1<T,S>,ExecutionContext)
T extends Object declared in interface Future …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些现有代码与play框架集成.我下载了1.3.6最小的Typesafe Activator软件包.我创建了一个play-java项目并build.sbt使用以下行修改了
文件:
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
libraryDependencies ++= Seq(
"com.xxx" % "messages" % "0.0.1-SNAPSHOT"
)
Run Code Online (Sandbox Code Playgroud)
然后我添加了对我现有的一个类的引用Application.java.当我运行时activator run,它下载了大量的jar,包括我手动添加并成功编译代码的jar.
当它试图运行时,我收到一个错误:
$ ./activator run
[info] Loading project definition from <APP_ROOT>/project
[info] Set current project to my-proj (in build file:<APP_ROOT>)
--- (Running the application, auto-reloading is enabled) ---
java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLoggingFilter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at akka.actor.ReflectiveDynamicAccess$$anonfun$getClassFor$1.apply(DynamicAccess.scala:67)
at akka.actor.ReflectiveDynamicAccess$$anonfun$getClassFor$1.apply(DynamicAccess.scala:66)
at scala.util.Try$.apply(Try.scala:192)
at …Run Code Online (Sandbox Code Playgroud)