java.lang.String cannot be converted to org.slf4j.Marker

本文解决了一个关于SLF4J日志框架中使用占位符参数时遇到的编译错误问题。作者尝试使用info方法记录日志,但遇到了参数类型不匹配的错误。文章详细解释了这一问题的原因,并提供了如何正确使用可变参数的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Question:

    

I'm using import lombok.extern.slf4j.Slf4j; for my class, and here's my log statement:log.info("{} : {} - {}", String1, String2, String3);

But it fails to compile and complaining the above line:java.lang.String cannot be converted to org.slf4j.Marker

Any ideas please?


Answer:

I guess that you are willing to use info(String format, Object... arguments) and are wondering why the method that is really called is info(Marker marker, String format, Object arg1, Object arg2).

This is related to Most Specific Method selection and Identify Potentially Applicable Methods.

As you have exactly four parameters, out of which three matches perfectly, the info(Marker marker, String format, Object arg1, Object arg2) method must be considered as "potentially matching".

You should read the documentation about variable arity parameters to get more details.


It works !


评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值