https://kotlinlang.org logo
Title
b

bbaldino

05/28/2019, 6:59 PM
is there any built-in annotation to suppress 'unused' warnings for methods in a library? i.e. 'API methods' used by other code. or a good way i could define one?
r

Ruckus

05/28/2019, 7:05 PM
Call them in tests :trollface:
5
c

Casey Brooks

05/28/2019, 7:31 PM
Or better yet, actually unit-test those methods 😂
b

bbaldino

05/28/2019, 8:36 PM
fair enough, but surely circumstances can exist where that may not always make sense. plus, i thought being explicit could be nice. so...does such an annotation exist?
p

Paulius Ruminas

05/29/2019, 5:39 AM
You could add
@file:Suppress("unused")
at the top of the file it will suppress all warnings in that file.
b

bbaldino

05/29/2019, 2:53 PM
thanks paulius. and it's easy to create an 'alias' for an annotation, isn't it? as in, if i wanted to define an annotation that was something like
@PublicAPI
but have it defined as basically
Suppress("unused")
?
p

Paulius Ruminas

05/29/2019, 4:06 PM
You can only alias the name
typealias PublicAPI = Suppress
so it would still have to be with an argument
@PublicAPI("unused")
.
b

bbaldino

05/29/2019, 5:19 PM
ah bummer. ok thanks.
k

karelpeeters

05/30/2019, 10:34 AM
Didn't know you could typealias annotations like that, that's interesting.