传递的参数多于格式字符串中实际使用的参数

发布于 2024-11-29 16:54:08 字数 290 浏览 4 评论 0原文

FindBugs 在以下代码中向我显示“传递的参数多于格式字符串中实际使用的参数”消息:

String.format("00", bd.getHour())

bd.getHour() 返回一个 int< /代码>。

有人可以澄清这一点吗?我的目标是确保 1 位整数前面有 0 (1 ->01, 13->13...)。

在没有收到 FindBugs 消息的情况下实现此目的的正确方法是什么?

FindBugs gives me a 'More arguments are passed than are actually used in the format string' message on the following code:

String.format("00", bd.getHour())

bd.getHour() returns an int.

Can someone clarify this? My obective is to make sure that 1 digit ints are preceded by a 0 (1 ->01, 13->13...).

What is the right way to achieve this without getting a FindBugs message?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

古镇旧梦 2024-12-06 16:54:08

String.format() 遵循 格式字符串,因此使用:

String.format("%02d", bd.getHour());

因为您的行将只打印 00 并忽略添加的参数。

String.format() follows the rules of format string, so use:

String.format("%02d", bd.getHour());

Because your line, will just print 00 and ignore the added parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文