MultiGauge.register should accept more types #5390
Labels
enhancement
A general enhancement
module: micrometer-core
An issue that is related to our core module
Milestone
Describe the bug
The typical way to use a
MultiGauge
is converting some list to a list ofRow
s using a Stream. This is also done in theMultiGaugeSample
example. Java's type inference is tricky here. In the example, it works because Java knows what is expected byMultiGauge.register
and infersList<Row<?>>
. But if you separate the conversion and assign the list to a variable, the inferred type isList<Row<Number>>
. The same is true for some reason if you use the newerStream.toList()
instead ofStream.collect(Collectors.toList())
.So
will compile but
and
will not.
I wonder if the type parameter of
Row
adds any value at all. But removing it would probably break existing code, so I suggest to change the signature ofMultiGauge.register
to accept anIterable<? extends Row<?>>
instead. Then it could also be called with aList<Row<Number>>
.I will create a PR for this small change.
Environment
java -version
]To Reproduce
See description
Expected behavior
List<Row<Number>>
is accepted and no ugly casts are necessary.The text was updated successfully, but these errors were encountered: