在Java的API文档说有关以下Collections.addAll
这种方便方法的行为与c.addAll(Arrays.asList(elements))的行为相同,但在大多数实现中,此方法可能运行得更快.
所以,如果我理解正确,a)比b)慢:
一个)
Collection<Integer> col = new ArrayList<Integer>();
col.addAll(Arrays.asList(1, 2, 3, 4, 5));
Run Code Online (Sandbox Code Playgroud)
b)
Collection<Integer> col = new ArrayList<Integer>();
// Collections.addAll(col, Arrays.asList(1, 2, 3, 4, 5)); <-- won't compile
Collections.addAll(col, 1, 2, 3, 4, 5);
Run Code Online (Sandbox Code Playgroud)
任何人都可以向我解释,为什么会这样?
编辑:更正的代码示例.thx到polygenelubricants
我需要在python中编写一个脚本来检查一个受kerberos保护的网页.有没有可能从python中做到这一点,以及如何?该脚本将部署在安装了python 2.4.something的linux环境中.
dertoni
PMD警告我要避免布尔实例化(出于效率原因).我有类似的东西
Boolean variable = new Boolean(somestringIGotRepresentingABoolean);
Run Code Online (Sandbox Code Playgroud)
我应该用这个
Boolean variable = Boolean.valueOf(somestringIGotRepresentingABoolean);
Run Code Online (Sandbox Code Playgroud)
为什么那更好?
在"Thinking in Java"一书中,有一个如何通过Reflection/Introspection获取bean信息的例子.
BeanInfo bi = Introspector.getBeanInfo(Car.class, Object.class);
for (PropertyDescriptor d: bi.getPropertyDescriptors()) {
Class<?> p = d.getPropertyType();
if (p == null) continue;
[...]
}
Run Code Online (Sandbox Code Playgroud)
在上面的示例的第4行中,检查PropertyType是否为null.何时以及在何种情况下会发生这种情况?你能给我举个例子吗?
我们在这里运行了几个java应用服务器,有几个应用程序.它们都使用Log4J登录到同一个文件系统,我们只是因为这个原因而创建的.有时会发生文件系统空间不足而应用程序崩溃的情况
log4j:ERROR Failed to flush writer,
java.io.IOException
Run Code Online (Sandbox Code Playgroud)
遗憾的是,Log4J无法从此错误中恢复,因此即使在文件系统中释放空间后,也不会再从该应用程序写入日志.除了重新启动应用程序之外,是否有任何选项,编程方式或设置方式,让Log4J再次运行?
在阅读一些Java源代码时,我遇到了这一行:
((Closeable) some_obj).close();
Run Code Online (Sandbox Code Playgroud)
some_obj显然是实现Closeable接口的类的实例.我的问题是,为什么他们在调用close()之前首先将some_obj强制转换为Closeable.我不能这样做
some_obj.close();
Run Code Online (Sandbox Code Playgroud) 我正在使用Axis2框架编写Web服务.该服务将充当DMZ中的代理.它实际上只是我们本地局域网中真实服务的中继.
该服务使用设置了mustUnderstand标志的标头.但由于代理服务相当简单,它无法理解这些头文件,它只是将请求中继到我们的局域网中,可以处理所有头文件.
问题是,Axis2检查标头并引发故障,因为通常读取和理解标头的模块不存在.
有没有办法配置Axis2,它确实忽略了mustUnderstand标志?
或者,从代码处理它的方法也是一种方法.
我有这样的协议:
#import <Foundation/Foundation.h>
@protocol Prot1 <NSObject>
@required
- (void)methodInProtocol;
@end
Run Code Online (Sandbox Code Playgroud)
这是我想要存储在这样的类中的委托的协议:
#import <Cocoa/Cocoa.h>
@class Prot1;
@interface Class1 : NSObject
@property (nonatomic, strong) Prot1 *delegate;
- (void)methodInClass;
@end
Run Code Online (Sandbox Code Playgroud)
这个类的实现是这样的:
#import "Class1.h"
#import "Prot1.h"
@implementation Class1
@synthesize delegate;
- (void)methodInClass {
[delegate methodInProt];
}
@end
Run Code Online (Sandbox Code Playgroud)
当我构建这些代码时,我收到以下错误:
Receiver type 'Prot1' for instance message is a forward declaration
Run Code Online (Sandbox Code Playgroud)
这有什么不对?我确实理解我必须通过@class为协议做一个前向声明,我认为我只需要#import协议,在类实现中......不是吗?
当我在Java中进行大量类型检查时,如下所示:
if (clazz.equals(Byte.class) <dosomething>
if (clazz.equals(Integer.class) <dosomething>
...
Run Code Online (Sandbox Code Playgroud)
JVM是否加载了所有这些类(Byte,Integer?)如果确实如此,是否还有其他方法可以在不加载一堆我甚至不需要的类的情况下进行类类型检查?
java ×7
performance ×2
axis2 ×1
casting ×1
classloader ×1
collections ×1
header ×1
idioms ×1
interface ×1
javabeans ×1
jvm ×1
kerberos ×1
log4j ×1
objective-c ×1
pmd ×1
protocols ×1
python ×1
reflection ×1
security ×1
soap ×1
web-services ×1