I get a warning: Extension is shadowed by a member...
# getting-started
n
I get a warning: Extension is shadowed by a member Is there some magic annotation which makes the extension higher priority than the member? Thanks.
๐Ÿšซ 2
๐Ÿ‘ 1
๐ŸŽ‰ 1
๐Ÿš€ 1
j
How would you expect it to work? What if the extension is not imported? You can't force consumers to add an import I guess, or it's no longer a matter of priority.
Why not just name the extension differently? What are you trying to do?
n
You are right, I didn't think about it ๐Ÿ˜… I'm creating a more-or-less type-safe wrapper around the JPA
EntityManager
. In my
TypeSafeEntityManager: EntityManager
sub-interface I have overridden
createQuery()
to require opt-in:
Copy code
@NotTypeSafeJpaApi
override fun createQuery(qlString: String): Query
But I also wanted to create an extension function:
Copy code
inline fun <reified T : Any> TypeSafeEntityManager.createQuery(qlString: String): TypeSafeQuery<T> = ...
Never mind, I will do something else, thanks for the answer ๐Ÿ™‚
> What if the extension is not imported? What I wanted is: โ€ข if the extension is not imported then the member is used (which requires opt-in) โ€ข if the extension is imported then it would have higher priority (magically ๐Ÿ™‚)
j
Then I guess your best course of action here is just to use another name for your extension
๐Ÿ‘๐Ÿป 1
You could even use a
@Deprecated
annotation instead of requiring opt-in, this way you can use
ReplaceWith
to automatically replace the call
๐Ÿ™ 1
y
I think also implementing
EntityManager
might not be what you want if you're trying to stop users from calling the unsafe methods. Instead, you can have a
@NotTypeSafeJpaApi val manager: EntityManager
exposed.
j
Yeah actually using a wrapper/decorator pattern would be a better approach
n
EntityManager
exposed
Good idea, thanks!