juliocbcotta
08/10/2022, 3:21 PMnonTransitiveRClass
in my project, but to avoid a bunch of import alias I thought I could encapsulate the R classes from library modules and avoid the class name conflict...
How to encapsulate the R
or R.string
class in my class ?
I tried this
object MyR {
val string: R.string = R.string
}
but I get thisephemient
08/10/2022, 3:28 PMR.string
is a class not an objectjuliocbcotta
08/10/2022, 3:29 PMjuliocbcotta
08/10/2022, 3:29 PMephemient
08/10/2022, 3:29 PMimport my.R as MyR
but will have to do so in every file that uses itjuliocbcotta
08/10/2022, 3:30 PMephemient
08/10/2022, 3:33 PMjuliocbcotta
08/10/2022, 3:34 PMephemient
08/10/2022, 4:15 PMjuliocbcotta
08/10/2022, 4:17 PMtseisel
08/10/2022, 8:18 PMtypealias
allowed referencing subclasses like this:
typealias MyR = com.my.package.R
val description = MyR.string.some_description
But it doesn't work. You could however define a typealias for each of R.string
, R.drawable
... but that's quite verbose.