0 我想出了一个似乎有效的解决方案。可能有更好的方法来做到这一点,但我现在所做的只是围绕强制转换操作执行 try-catch 块。 例如: 尝试 { inputAASequence = (AminoAcidSequenceDocument) 文档[0].getDocument(); doctype = "氨基酸"; }捕获(例外 e){尝试 { inputNtSequence = (NucleotideSequenceDocument) 文档[0].getDocument(); doctype = "核苷酸"; }捕获(例外 e){ throw (new DocumentOperationException("无法确定输入文档的类型")); } } 肖恩·约翰逊 2019年1月3日16:27 0 票分享 评论动作 永久链接
0 我找到了另一种方法来做到这一点。我认为这种方式实际上是首选方式。 如果 (DocumentType.isAminoAcidSequence(documents[0].getDocument())) { //做氨基酸的东西}否则 if (DocumentType.isNucleotideSequence(documents[0].getDocument())) { //做核苷酸的事情}别的 { throw (new DocumentOperationException("输入文档必须是核苷酸序列或氨基酸序列。")); } 肖恩·约翰逊 2019年1月3日18:32 0 票分享 评论动作 永久链接