我想创建一个二维数组,我想在其中存储数据库中的记录.所以我要说第一个是类型int
,第二个是类型String
(这里我只描述了一个记录,所以基本上是db列的类型).我该怎么做?数组是否是正确的数据结构?
简而言之,JVM是否在内部优化了以下代码
public void test(String str)
{
int a = 0;
for( int i = 0; i < 10; i++)
{
a = a + str.length();
}
}
Run Code Online (Sandbox Code Playgroud)
表现得如下:
public void test(String str)
{
int len = str.length();
int a = 0;
for( int i = 0; i < 10; i++)
{
a = a + len;
}
}
Run Code Online (Sandbox Code Playgroud)
如果它确实优化了,它是通过在内部缓存str.length()值来实现的吗?
我正在使用ASM Java库来替换一些反射.我生成了这个方法的主体:
void set(Object object, int fieldIndex, Object value);
Run Code Online (Sandbox Code Playgroud)
使用此生成的方法,我可以在运行时在不使用反射的情况下在对象上设置字段.它很棒.但是,我发现原始字段失败了.这是我的set方法的相关部分:
for (int i = 0, n = cachedFields.length; i < n; i++) {
mv.visitLabel(labels[i]);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, targetClassName);
mv.visitVarInsn(ALOAD, 3);
Field field = cachedFields[i].field;
Type fieldType = Type.getType(field.getType());
mv.visitFieldInsn(PUTFIELD, targetClassName, field.getName(), fieldType.getDescriptor());
mv.visitInsn(RETURN);
}
Run Code Online (Sandbox Code Playgroud)
此代码为选择生成案例标签.它适用于对象,但对于原语,我收到此错误:
期待在堆栈上找到浮动
好的,这是有道理的,我需要自己进行拆箱.我实现了以下内容:
for (int i = 0, n = cachedFields.length; i < n; i++) {
mv.visitLabel(labels[i]);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, targetClassName);
mv.visitVarInsn(ALOAD, 3);
Field field = …
Run Code Online (Sandbox Code Playgroud) 当我尝试编译以下代码时,我得到编译错误:
unexpected type System.out.println( new Test().C.i );
^
required: class,package
found: value
Run Code Online (Sandbox Code Playgroud)
class Test {
class C {
static final int i = 0;
}
public static void main(String... z) {
System.out.println( new Test().C.i );
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变 new Test().C.i
到new Test().new C().i
它编译就好了.
为什么?如果我在C中是静态的,那么我不应该实例化C.我应该只能通过类C而不是C对象来调用它.
我错过了什么?
我只是尝试使用Cloud9 ide,我成功地将我的github存储库分叉并将settings.xml放到$ HOME/.m2 /目录中.
当我尝试构建mvn clean install时,我遇到了以下错误
[INFO] Error building POM (may not be this project's POM).
Project ID: com.temenos.interaction:com.temenos.interaction.rimdsl.parent
Reason: Cannot find layout implementation corresponding to: 'p2' for remote repository with id: 'p2.eclipse.kepler'. for project com.temenos.interaction:com.temenos.interaction.rimdsl.parent
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Cannot find layout implementation corresponding to: 'p2' for remote repository with id: 'p2.eclipse.kepler'. for project com.temenos.interaction:com.temenos.interaction.rimdsl.parent
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:404)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:272)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at …
Run Code Online (Sandbox Code Playgroud) 我的一个朋友在Java API中找到了这个小问题(https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html),
Class Enum<E extends Enum<E>>
Run Code Online (Sandbox Code Playgroud)
并阅读以下文章https://docs.oracle.com/javase/tutorial/java/generics/genTypes.html我可以理解上述行在语法上的含义,但从给出的例子中我无法弄清楚用例这超出了Enum类(查看来源).
我想更多地了解上述可能存在解决方案的问题.
我正在开发一个OpenCV程序来查找从相机到具有已知宽高比的矩形的距离.从正面视图中查找到矩形的距离可以正常工作:
实际距离非常接近于此计算的距离:
wtarget · pimage d = c —————————————————————————— 2 · ptarget · tan(?fov / 2)
其中w target是目标的实际宽度(以英寸为单位),p image是整个图像的像素宽度,p target是检测到的四边形的最大宽度(以像素为单位)的长度,θfov是FOV我们的摄像头.然后将其乘以某个常数c.
从非正向的透视图中查看目标矩形时会发生此问题:
这两个方向之间的实际距离差异很小,但检测到的距离相差近2英尺.
我想知道的是如何一致地计算距离,考虑到不同的透视角度.我已经尝试过getPerspectiveTransform
,但这需要我知道目标的最终比例 - 我只知道纵横比.
这两种通用方法有什么区别吗?
public static <E> void fill(ArrayList<? extends Comparable<? super E>> a)
public static <E extends Comparable<? super E>> void fill2(ArrayList<E> a)
在声明方法时,参数的各种前缀是什么意思?
sh(*cmd, &block)
Run Code Online (Sandbox Code Playgroud)
什么是*
之前cmd
是什么意思?
什么是&
之前block
是什么意思?
我过去没有这样做过,所以我可能会在这里遗漏一些东西.
我在本地更改了'ruby-git'的Gem文件,它运行正常.在我的Github回购中,我分叉了一个宝石并对它进行了相同的更改.
在构建Sinatra应用程序以将其推送到Heroku时,我更改了Gemfile
如下:
gem 'git', :git => "git://github.com/silverSpoon/ruby-git.git"`
Run Code Online (Sandbox Code Playgroud)
当我跑步时bundle install
,我明白了
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rugged 0.21.0
Using sinatra 1.4.5
Using git 1.2.8 from git://github.com/silverSpoon/ruby-git.git (at master)
Your bundle is complete!
Run Code Online (Sandbox Code Playgroud)
? gem list git
,它没有显示安装的宝石. ? bundle show git
,它显示了安装gem repo的路径 -/Users/jatinganhotra/.rvm/gems/ruby-2.1.3@527website/bundler/gems/ruby-git-c7fb35af1a99
irb
并执行2.1.3 :001 > require 'git'
LoadError: cannot load such file -- git
我在这里想念傻事吗?