Comments (6)
I'm guessing some issue with the Kotlin generics compatibility, so reporting there was def. the right approach
@maxtroy I assume there's not much we can do with the use of generics here, fixing in Kotlin is the only way forward?
from agera.
We can't really do anything, I'm afraid.
Because Android Studio is the recommended way to program Android code, the current design places Android Studio use case first, making sure the IDE sees the right types and auto-completes the right subset of methods available at any given state.
The generics we use in the repository compiler are a bit quirky (and towards the verbose/redundant end of the spectrum), due to Android Studio (or IntelliJ) internal type checker having some difference with the real Java compiler. In particular, Android Studio does NOT like the following class hierarchy:
interface Base<T> {}
interface X<T> extends Base<X<T>> {}
interface Y<T> extends Base<Y<T>> {}
@SuppressWarnings({"rawtypes", "unchecked"})
interface Compiler extends X, Y {}
With the error that "Base<T>
cannot be extended with different type parameters", despite the explicit request to ignore the type parameters (suppressing raw types and unchecked casts warnings).
Note that this is IntelliJ-only; the real Java compiler has no issues with this hierarchy. This bug has been reported more than one year ago, with no official solution so far. The way we work around this IntelliJ limitation is to allow the "different" type parameters to unify:
interface Base<T> {}
interface X<T, S extends X<T, S>> extends Base<S> {}
interface Y<T, S extends Y<T, S>> extends Base<S> {}
@SuppressWarnings({"rawtypes", "unchecked"})
interface Compiler extends X, Y {}
Because in this way, the ("unnecessarily smart") IntelliJ type inference system can find a common subclass S that extends both X<T, S>
and Y<T, S>
(aka Compiler), so the interface Base<S>
is inherited with the same type parameter.
I'm guessing that the Kotlin compiler might not be able to handle this type hierarchy and gives up at some point.
from agera.
Closing this, since there's not much that can be done in Agera. Kotlin promises Java interop. so hopefully KT-14725 can be resolve soon.
from agera.
Hoping this helps.
fun <F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.asT(c: Class<T>? = null): RepositoryCompilerStates.RFlow<T, T, *> = this as RepositoryCompilerStates.RFlow<T, T, *>
fun <F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.asResultT(c: Class<T>? = null): RepositoryCompilerStates.RFlow<Result<T>, T, *> = this as RepositoryCompilerStates.RFlow<Result<T>, T, *>
@TestOnly
fun test(): Repository<Result<String>> {
return Repositories.repositoryWithInitialValue(Result.absent<String>())
.observe()
.onUpdatesPerLoop()
.goTo(Executors.threadPollExecutor())
.asT(Result::class.java)
.attemptGetFrom { Result.present("123") }
.orEnd { Result.failure<String>() }
.check { it.isNotEmpty() }
.orEnd { Result.failure() }
.asResultT(String::class.java)
.sendTo { Log.e("TTEST", "sendTo") }
.asResultT(String::class.java)
.transform { "111" }
.thenTransform { Result.present(it) }
.notifyIf { _, _ -> true }
.onConcurrentUpdate(RepositoryConfig.SEND_INTERRUPT)
.compile()
}
from agera.
@sfcecy7i Should work with reified
too.
inline fun <reified F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.typed(): RepositoryCompilerStates.RFlow<T, T, *> = this as RepositoryCompilerStates.RFlow<T, T, *>
inline fun <reified F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.typedResult(): RepositoryCompilerStates.RFlow<Result<T>, T, *> = this as RepositoryCompilerStates.RFlow<Result<T>, T, *>
@TestOnly
fun test(): Repository<Result<String>> {
return Repositories.repositoryWithInitialValue(Result.absent<String>())
.observe()
.onUpdatesPerLoop()
.goTo(Executors.threadPollExecutor())
.typed<Result>()
.attemptGetFrom { Result.present("123") }
.orEnd { Result.failure<String>() }
.check { it.isNotEmpty() }
.orEnd { Result.failure() }
.typedResult<String>()
.sendTo { Log.e("TTEST", "sendTo") }
.typedResult<String>()
.transform { "111" }
.thenTransform { Result.present(it) }
.notifyIf { _, _ -> true }
.onConcurrentUpdate(RepositoryConfig.SEND_INTERRUPT)
.compile()
}
from agera.
@LouisCAD Thanks for your advice.
inline fun <reified TPre, reified TVal> RepositoryCompilerStates.RFlow<*, *, *>.reify() = this as RepositoryCompilerStates.RFlow<TVal, TPre, *>
inline fun <reified TVal> RepositoryCompilerStates.RFlow<*, *, *>.reify1() = this as RepositoryCompilerStates.RFlow<TVal, *, *>
@TestOnly
fun test(): Repository<Result<String>> {
return Repositories.repositoryWithInitialValue(Result.absent<String>())
.observe()
.onUpdatesPerLoop()
.goTo(KExecutors.threadPollExecutor())
.reify1<Result<String>>()
.attemptGetFrom { Result.present("success") }
.orEnd { Result.failure<String>() }
.check { it.isNotEmpty() }
.orEnd { Result.failure() }
.sendTo { Log.e("TAG", "result: $it") }
.reify<String, Result<String>>()
.transform { "$it end" }
.thenTransform { Result.present(it) }
.notifyIf { _, _ -> true }
.onConcurrentUpdate(RepositoryConfig.SEND_INTERRUPT)
.compile()
}
from agera.
Related Issues (20)
- Compilation problems HOT 1
- Crash when trying to remove not added updatable HOT 1
- Add the 1.2.0 release to the GitHub releases screen HOT 1
- Exception when Response is Empty HOT 4
- [Question] Usages of non main thread to register an Updatable to a BaseObservable? HOT 5
- Wish to support Kotlin language.
- crash bug HOT 3
- About IdentityMultimap query. HOT 3
- Is this library dead? HOT 2
- [question] Push Event on a high speed frequency, Pull Data will too busy to attend to all HOT 2
- Query HOT 3
- [Query]: About switch work-thread HOT 10
- Agera 是否支持线程并发再合并? HOT 1
- #44
- (gradle4.4.1, agera1.4.0) when I run proguard, I got these warnings:
- Could not find dependency "com.google.android.agera:agera:1.4.0" HOT 6
- Sample doesn't build, is this project dead? HOT 7
- Androidx支持
- Deploy the last artifact outside of jcenter HOT 1
- Security Policy violation Binary Artifacts HOT 41
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from agera.