Getting an error on the `tag` within my `start` me...
# getting-started
m
Getting an error on the
tag
within my
start
method saying:
Required:
Tag<T#1 (type parameter of com.revl.metrics.Timer1.start)>
Found:
Tag<T#2 (type parameter of com.revl.metrics.Timer1)>
k
You have two different `T`'s, either that's a mistake or you should at least give them different names.
s
If you're trying to reuse the same
T
generic type argument defined in your class, remove the second definition of
T
in the function:
Copy code
fun start(): NeedsTag1<T, StartedTimer> {
Because what you have right now, and I think you have not noticed, is:
Copy code
class Timer1<T : TagValue>(
//...
fun <U : TagValue> start(): NeedsTag1<U, StartedTimer> {
where
T
and
U
are not the same types. Calling it with the same name won't do what you expect here. I assume, by the nature of the error, that NeedsTag1 needs a tag of the same type passed as the first generic type argument (
U
in my example), so if this is true, you need to pass a
Tag<U>
to the constructor. However, your
tag
value of the class is of type
Tag<T>
!
📖 1