我注意到哈希函数代码作为其中的一部分java.util.Hashtable#get(K key)执行以下操作:int index = (hash & 0x7FFFFFFF) % tab.length;.这个二进制'和'操作只是为了重置符号位吗?因此避免负表访问.
更新:他们'和'与0x7FFFFFFF而不是0xEFFFFFFF的事实让我感到困惑.为什么符号需要一个完整的字节而不是一个比特?
对于一些特殊用例,我有一个小实用程序,可以使用动态类加载器从jar加载Java类DynamicClassLoader.这适用于jar中包含的Java类.从jar加载Scala类也可以正常工作.但是,实例化加载的Scala类会导致以下异常.看起来Scala类有私有默认构造函数?注意编译的Scala类名以.结尾$
java.lang.IllegalAccessException: Class XXX can not access a member of class ScalaClassYYY$ with modifiers "private"
Run Code Online (Sandbox Code Playgroud)
下面的代码片段说明了我想要实现的目标,并提供了更多的上下文.例外情况发生在带注释的行:
// deploy and register the new code
byte[] jarBytes = (byte[]) ((Object) message.getAttachment("jar"));
String registerClassName = message.getAttachment("register");
logger.debug("the register is '" + registerClassName + "'");
DynamicClassLoader loader = new DynamicClassLoader(jarBytes);
Class<?> registerClass = loader.lookUp(registerClassName);
// ===> this is where the java.lang.IllegalAccessException happens
IRegisterExecutor registerExecutor = (IRegisterExecutor) registerClass.newInstance();
registerExecutor.register();
Run Code Online (Sandbox Code Playgroud)
任何想法如何解决?
我有一个Java/Scala mix Maven项目.我需要重用一个Saddle方法make,该方法具体定义为被称为trait的一部分Index.如果这有任何帮助,则在此定义该方法.我已经打过电话使用从Java该方法Index.make或Index$class.make但在这两种情况下,我得到的error: cannot find symbol编译错误.
有没有办法从Java调用具体的Trait方法?
我遵循这篇文章每个C++开发人员应该使用的十个C++ 11特性,并在Move语义示例的代码中添加了一些基本的跟踪,并且看到移动构造函数永远不会被调用,并且想知道为什么.我尝试过两个编译器GNU 4.6.3和Intel 15.0.0,结果是一样的.
我这样编译:
# using Intel compiler
icpc -Wall -g -Wno-shadow -std=c++0x -o showcase ./showcase.cpp
# using gnu g++ compiler
g++ -Wall -g -Wno-shadow -std=gnu++0x -o showcase ./showcase.cpp
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出,当它应该在第133行时不调用移动构造函数:
instantiating b1 ...
Buffer() default constructor invoked
my name is:
instantiating b2 ...
Buffer(const std::string& name, size_t size) constructor invoked
my name is: buf2
instantiating b3 ...
Buffer(const Buffer& copy) copy constructor invoked
my name is: buf2
instantiating b4 ...
Buffer(const std::string& name, size_t size) …Run Code Online (Sandbox Code Playgroud) 来自Java/C++之类的语言,我们习惯于部分或抽象的类实现,例如
protocol ProtocolA {
func x()
func y()
}
// attempt to partially implement ProtocolA
class AbstractProtocolA: ProtocolA {
func x() { /* implementation */ }
// does not implement function y
}
class ConcreteA1: AbstractProtocolA {
func y() { /* implementation */ }
}
class ConcreteA2: AbstractProtocolA {
override func x() { /* implementation */ }
func y() { /* implementation */ }
}
Run Code Online (Sandbox Code Playgroud)
但这在Swift中是不可能的,在这种情况下我会得到编译错误Type 'AbstractProtocolA' does not conform to protocol 'ProtocolA'...是否有另一种Swifty方法来覆盖这个OOD用例?
更新: 规避这种限制的方法是:
enum ProtocolAError: ErrorType …Run Code Online (Sandbox Code Playgroud) 我有一个 Maven 项目,我正在使用scalatest-maven-plugin来配置 scalatest。我正在使用 scalatest 3.0.0,但是我无法标记和过滤整个套件。
作为参考,我使用了博客标记整个 ScalaTest 套件(Java 8 的更新),但这似乎不适用于 Maven。
我创建了一个新Skip标签,定义如下:
package tags;
import java.lang.annotation.*;
@org.scalatest.TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Skip {}
Run Code Online (Sandbox Code Playgroud)
然后我像这样标记我的测试套件:
@tags.Skip
class AcceptanceTest extends FeatureSpec { ...
Run Code Online (Sandbox Code Playgroud)
然后我像这样配置我的 scalatest-maven-plugin:
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<configuration>
<tagsToExclude>tags.Skip</tagsToExclude>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
然后运行mvn clean install -X我看到(它正确地将 -l 标签排除 CLI 参数传递给 Scalatest):
[DEBUG] Forking ScalaTest via: cmd.exe /X /C "java -Dbasedir=mydir
org.scalatest.tools.Runner -R -l tags.Skip …Run Code Online (Sandbox Code Playgroud) 我有一个Python应用程序调用C++ boost python库,它都可以工作.但是,我有一个回调C++到Python的场景,其中来自boost线程的C++调用python,我在C++端获得访问冲突.如果我使用python线程执行完全相同的回调,它可以完美地工作.因此我怀疑我不能简单地使用boost线程从C++回调Python,但需要做一些额外的工作吗?
我有以下简化的用例.基本上我有一些ggplot2图,我想与另一个使用基本图形库plot.new()等生成的图结合:
p1 <- generate_ggplot1(...)
p2 <- generate_ggplot2(...)
p3 <- generate_ggplot3(...)
# how to get hold of the plot output and make it available as
# p4 for arrangeGrob?
plot.new()
...
final <- gridExtra::arrangeGrob(p1, p2, p3, p4, layout_matrix = rbind(c(1,2), c(3,4)), widths=c(7,7), heights=c(7,7))
ggplot2::ggsave(filename=output.file,plot=final,width=14,height=14)
Run Code Online (Sandbox Code Playgroud)
有什么选择呢?与重写p4分开是原生的ggplot2
我有一个图,其中每个点都有点、线和注释。问题是行最终会穿过注释文本,我想找到一个解决方案来避免这种情况,例如如何使注释位于“顶部”?
我的伪 ggplot 是这样的:
# some df
ggplot(df,aes(x=x,y=y)) + geom_line() + geom_point() +
annotate('text', ...)
Run Code Online (Sandbox Code Playgroud)
请注意,如果我交换顺序geom_line,geom_point线条将绘制在该点的顶部(当然,当颜色不是黑色或存在透明度时)。但是,该线将直接穿过注释文本。
我该如何解决这个问题?到目前为止,我选择不包含线条,但会很好。
我使用 PyScaffold 设置我的项目,并在使用 pytest 运行单元测试时收到以下第三方警告,我想摆脱它,但不知道如何:
==================================== warnings summary ====================================
c:\dev\pyrepo\lib\site-packages\patsy\constraint.py:13
c:\dev\pyrepo\lib\site-packages\patsy\constraint.py:13: DeprecationWarning: Using or importing
the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in
3.9 it will stop working
from collections import Mapping
-- Docs: https://docs.pytest.org/en/latest/warnings.html
Run Code Online (Sandbox Code Playgroud)
避免像这样的第三方库发出警告而不是我自己的项目代码警告的最佳方法是什么?