SLF4J varargs interprets first string as marker

When using

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

SLF4J complains as follows

[javac] sourcefile.java:105: error: incompatible types: String cannot be converted to Marker
[javac] log.trace("with name {}, duration {}, repetitions {}",
[javac] ^
[javac] Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
[javac] 1 error

Using

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

solves the problem, yet seems kludgey. (Especially since the API allows 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.

Is there a way to use the varargs constructor in SLF4J for Android? Is there an alternative?


Seems like a bug in the API.

Varargs are used, but for the Marker methods there are also defined methods with 1, 2 and 3 arguments.

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.

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

For me Varargs do work with 1, 2, or 4, arguments.

Its only a problem with 3 arguments.

Its fixed in 1.7 by changing the highlighted Object to a String.


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

log.trace("with name {0}, duration {1}, repetitions {2}", name, duration, repetitions);
链接地址: http://www.djcxy.com/p/30156.html

上一篇: 提出请求时,Google API客户端库在IIS中冻结

下一篇: SLF4J可变参数将第一个字符串解释为标记