我期待在maven存储库中找到guava-libraries.看起来guava正在为google-collections库添加更多功能.
在ArrayBlockingQueue,所有需要锁的方法final在调用之前将其复制到局部变量lock().
public boolean offer(E e) {
if (e == null) throw new NullPointerException();
final ReentrantLock lock = this.lock;
lock.lock();
try {
if (count == items.length)
return false;
else {
insert(e);
return true;
}
} finally {
lock.unlock();
}
}
Run Code Online (Sandbox Code Playgroud)
当字段是什么时,有没有理由复制this.lock到局部变量?lockthis.lockfinal
此外,它还在使用E[]之前使用本地副本:
private E extract() {
final E[] items = this.items;
E x = items[takeIndex];
items[takeIndex] = null;
takeIndex = inc(takeIndex);
--count;
notFull.signal();
return x;
}
Run Code Online (Sandbox Code Playgroud)
有没有理由将最终字段复制到本地最终变量?
BlockingQueue有一个名为drainTo()的方法,但它没有被阻止.我需要一个我想阻止的队列,但也能够在一个方法中检索排队的对象.
Object first = blockingQueue.take();
if ( blockingQueue.size() > 0 )
blockingQueue.drainTo( list );
Run Code Online (Sandbox Code Playgroud)
我想上面的代码会起作用,但我正在寻找一个优雅的解决方案.
我们将maven和git一起用于Java项目.在<scm>部分中,<tag>由发布插件自动添加.
例如,
<scm>
<connection>scm:git:http://myserver:7990/scm/project/test.git</connection>
<tag>releaes-tag</tag>
</scm>
Run Code Online (Sandbox Code Playgroud)
<tag>这里有什么代表?
我认为正常的惯例是 <tag>HEAD</tag>.
当我们使用颠覆时,maven从未使用过 <tag></tag>
是什么意思<tag></tag>?
我搜索了谷歌和maven文档,但我找不到任何信息.
我正在使用google-collections并尝试找到满足谓词的第一个元素,如果没有,请返回'null'.
不幸的是,当没有找到元素时,Iterables.find和Iterators.find抛出NoSuchElementException.
现在,我被迫做了
Object found = null;
if ( Iterators.any( newIterator(...) , my_predicate )
{
found = Iterators.find( newIterator(...), my_predicate )
}
Run Code Online (Sandbox Code Playgroud)
我可以通过'try/catch'进行环绕并做同样的事情但是对于我的用例,我会遇到很多没有找到元素的情况.
有更简单的方法吗?
我们几个月来一直在制作中使用Google收藏.我们想开始使用番石榴来增加其他功能.但是,我害怕将番石榴带入我们的产品堆栈b/c一些开发人员可能会开始使用'beta'类.
我们的代码中有各种单元测试,但在这一点上,我不希望包含'beta'类b/c,它将来会发生变化.
如果项目包含任何'beta'番石榴类,有没有简单的方法来检测?
如何发送输出println()到System.err.我想使用字符串模板.
val i = 3
println("my number is $i")
Run Code Online (Sandbox Code Playgroud)
println()将消息发送到stdout,看起来没有选项发送到stderr.
我开始大量使用Java注释.一个例子是使用注释方法并将它们转换为基于'telnet'的命令行命令.我这样做是通过解析注释并挂钩到jopt选项解析器.
但是,我手动做了很多这些.例如,Method参数注释处理..
Method method = ... //;
Class[] parameters = method.getParamterTypes();
Annotation[][] annotations = method.getparamterAnnotations();
for( int i = 0; i < parameters.length; i++ )
{
// iterate through the annotation , see if each param has specific annotation ,etc.
}
Run Code Online (Sandbox Code Playgroud)
这是多余和乏味的.
是否有任何开源项目有助于处理注释?
java ×6
guava ×3
maven ×2
annotations ×1
concurrency ×1
final ×1
git ×1
kotlin ×1
maven-scm ×1
optimization ×1