- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在处理的一个项目有以下代码:
val ftr1: Future[Try[(Date, String)]] = Future {
if (someCondition) {
// some code
val amazonClient = Try[new com.amazonaws.services.s3.AmazonS3Client(...)]
amazonClient.map { c =>
// doing some stuff
(new Date, "SomeString")
}
} else {
// some code
Failure(new Exception)
}
}
Future.firstCompletedOf(Seq(ftr1, anotherFuture)) map {
case t: Try[(Date, String)] => {
t match {
case Success(r) => //do some things
case _ => //do some another things
}
case _ => //do some another things
}
[warn] non-variable type argument java.util.Date in type pattern java.util.Date, String) is unchecked since it is eliminated by erasure
[warn] case t: (Date, String) => //do some things
最佳答案
Try[+T]
是一个抽象类,您不能为其创建实例。
有两个案例类继承自它,Success
和 Failure
,您应该真正使用它。
编译器警告您,在编译时,类型删除将删除这些类型,因此对它们进行匹配不会得到您想要的结果。有关更多信息,请访问 How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?
但是,如果您只需匹配 Success
就可以完全避免这一切。和 Failure
减少比赛中不必要的嵌套:
val ftr1: Future[Try[(Date, String)]] = Future {
if (someCondition) {
// some code
val amazonClient = Try { /* stuff */ }
amazonClient.map { c =>
// doing some stuff
(new Date, "SomeString")
} else Failure(new Exception)
}
Future.firstCompletedOf(Seq(ftr1, anotherFuture)) map {
case Success((date, myString)) => /* do stuff */
case Failure(e) => log(e)
}
关于scala - 如何避免 'Non-variable type argument is unchecked since it is eliminated by erasure' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38618071/
Scenario A.java-----------after erasure-------->M.class Scenario B.java-----------after erasure-----
我最近偶然发现一段代码由于“相同的删除”问题而无法在我的 Eclipse 中编译(看起来与 this one 非常相似)。编写代码的人向我保证,它可以在他们的本地环境和他们的持续集成中编译,所以我一起
我有以下代码但它不起作用:出现错误 both methods have same erasure。 public class Foo { public static void main(St
我第一次在 Java 中使用泛型,我面临一个我无法克服的问题:为什么编译: public interface Aa{} public interface Bb{} public interface C
我正在尝试使用 Option.getOrElse()方法,但它返回 etiher Any或 ScalaObject而不是 Option 的正确类的实例被参数化了。我找不到有关此问题的任何提及,而且似乎
这个问题已经有答案了: interface and a class. name clash: same erasure, yet neither overrides other (3 个回答) 已关闭
我有一个特征和两个扩展它的案例类: trait Authenticatable { val email: String val pass: String val id: Long va
所以我有这个界面 public interface EventHandler { public void handleEvent(E event); } 我想为它派生处理事件的类,如下所示
斯卡拉 2.8.1 我已经使用解析器/组合器实现了一个非常简单的外部 DSL,用于 QA 编写验收测试。 最近我添加了循环遍历一组表达式的功能 sealed trait Expr ... //inse
我目前正在尝试编写一个双向映射,因为(据我所知)Java 没有提供双向映射。我的代码如下。 private static final class ColourCharTwoWayMap { p
通过使用泛型,我们可以在编译期间检测到任何可能的情况。例如, List list = new ArrayList(); //list.add(new Integer(45)); This will c
我有一个类定义了以下两个方法: public Map> method(final Map> data) public boolean method(final Map data) 基于泛型的 Java
我正在尝试设置 Hadoop 3 集群。 关于纠删码功能的两个问题: 如何确保启用纠删码? 我还需要将复制因子设置为 3 吗? 请指出与纠删码/复制相关的相关配置属性,以获得与 Hadoop 2(复制
比较这两种技术的优点/缺点是什么?更重要的是:为什么以及何时应该使用一个而不是另一个?这只是个人品味/偏好的问题吗? 尽我所能,我还没有找到其他明确解决我问题的帖子。在有关多态性和/或类型删除的实际使
我无法理解 asObservable method 的基本原理和目的在 RxSwift 的 Observable class . /// A type-erased `ObservableType`.
我一直在尝试但未能模仿 Baeldung article的演练如何触发“子”实体的保存:通过 Spring Boot 的 @DBRef 注释“包含”在另一个实体中的实体。就我而言,我正在尝试从客户那里
您好,我想重写自定义类 MyList 中的构造函数。 下面的代码可以编译,我收到“相同删除”错误。对于编译器List与 List 类型相同 有人可以建议我如何解决这个问题吗?我尝试使用 List并使用
这个问题在这里已经有了答案: Where and why do I have to put the "template" and "typename" keywords? (8 个答案) 关闭 7
我的任务是使用奇偶校验和方法和 Reed-Solomon Erasure Correction 对一些声音字节进行编码和解码。 .我已经完成了第一种方法(奇偶校验和)的编码,但需要帮助完成第二种方法,
我有一个接口(interface),当我尝试实现它的一种方法时,我得到了这个错误:“名称冲突:GenericQueue 中的 enqueue(T#1) 和 IGenericQueue 中的 enque
我是一名优秀的程序员,十分优秀!