我正在阅读鲍勃叔叔的《干净的代码》。在第 16 章中,本书展示了如何重构示例。有一部分我无法理解这样写的目的。
_getMinimumYear()下划线开头?public abstract int getMinimumYear();public abstract class DayDateFactory {
private static DayDateFactory factory = new SpreadsheetDateFactory();
public static void setInstance(DayDateFactory factory) {
DayDateFactory.factory = factory;
}
protected abstract DayDate _makeDate(int ordinal);
protected abstract DayDate _makeDate(int day, Month month, int year);
protected abstract DayDate _makeDate(int day, int month, int year);
protected abstract DayDate _makeDate(java.util.Date date);
protected abstract int _getMinimumYear();
protected abstract int _getMaximumYear();
public static DayDate makeDate(int ordinal) { …Run Code Online (Sandbox Code Playgroud) 我遇到一个问题,以下代码无法在 kotlin 中编译。
// StateModel.kt
sealed class StateModel
class Loading : StateModel()
data class Success<T: Any>(val data: T) : StateModel()
data class MyError(val message: String) : StateModel()
// StateModelTransformer.kt
class StateModelTransformer<T: Any> : FlowableTransformer<T, StateModel> {
override fun apply(upstream: Flowable<T>): Publisher<StateModel> {
return upstream
.map { data -> Success(data) }
.onErrorReturn { error ->
MyError(error.message) // compile error, Type mismatch, Require Success<T>, Found MyError
}
.startWith(Loading()) // compile error, none of the following function can be called with the arguments …Run Code Online (Sandbox Code Playgroud) Google的Guava库提供了一个很棒的类Range,它有很多有用的方法,比如greaterThan(x),open(x,y)等等.我想知道是否有任何方法可以应用这种方法来生成一个随机数Range?