简体   繁体   English

SLF4J varargs将第一个字符串解释为标记

[英]SLF4J varargs interprets first string as marker

When using 使用时

log.trace("with name {}, duration {}, repetitions {}", name, duration, repetitions);

SLF4J complains as follows SLF4J抱怨如下

[javac] sourcefile.java:105: error: incompatible types: String cannot be converted to Marker [javac] sourcefile.java:105:错误:类型不兼容:字符串无法转换为标记
[javac] log.trace("with name {}, duration {}, repetitions {}", [javac] log.trace(“名称为{},持续时间为{},重复次数为{}”,
[javac] ^ [javac] ^
[javac] Note: Some messages have been simplified; [javac]注意:一些消息已经简化。 recompile with -Xdiags:verbose to get full output 用-Xdiags:verbose重新编译以获取完整输出
[javac] 1 error [javac] 1个错误

Using 使用

log.trace("with name {}, duration {}, repetitions {}",
      new Object[]{name, duration, repetitions});

solves the problem, yet seems kludgey. 解决了问题,但似乎很笨拙。 (Especially since the API allows varargs). (特别是因为API允许使用varargs)。

Going by this answer seems to say that upgrading to SLF4J 1.7 would solve the problem, yet the android-slf4j is at 1.6.1 . 回答这个问题似乎意味着升级到SLF4J 1.7可以解决问题,但是android-slf4j的版本为1.6.1

Is there a way to use the varargs constructor in SLF4J for Android? 有没有一种方法可以在Android的SLF4J中使用varargs构造函数? Is there an alternative? 还有其他选择吗?

Seems like a bug in the API. 似乎是API中的错误。

Varargs are used, but for the Marker methods there are also defined methods with 1, 2 and 3 arguments. 使用了Varargs,但是对于Marker方法,还定义了带有1、2和3参数的方法。

log.trace(Marker, Object...)
log.trace(Marker, Object)
log.trace(Marker, Object, Object)
log.trace(Marker, **Object**, Object, Object)

However the String APIs, only have varargs and 1 and 2 arg methods. 但是,字符串API仅具有varargs以及1和2 arg方法。

log.trace(String, Object...)
log.trace(String, Object)
log.trace(String, Object, Object)

For me Varargs do work with 1, 2, or 4, arguments. 对我来说,Varargs可以使用1、2或4参数。

Its only a problem with 3 arguments. 这只是3个参数的问题。

Its fixed in 1.7 by changing the highlighted Object to a String. 通过将突出显示的对象更改为字符串在1.7中进行了修复。

尝试使用以下示例代码解决您的问题:

log.trace("with name {0}, duration {1}, repetitions {2}", name, duration, repetitions);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM