首页 \ 问答 \ Java Abstract Class声明throwable - 实现不会强制执行它?(Java Abstract Class declares throwable - implementation does not enforce it? [duplicate])

Java Abstract Class声明throwable - 实现不会强制执行它?(Java Abstract Class declares throwable - implementation does not enforce it? [duplicate])

这个问题在这里已有答案:

我想知道使用抽象类和接口之间的区别,这让我感到困惑:

假设你有一个抽象类

public abstract class Animal {   
//return the tail lenght of the animal
public abstract int getTailLength() throws IllegalStateException;
}

承诺抽象类的实现有一个名为getTailLength()的方法[编译器强制扩展类为@override抽象类并实现它们],如下所示:

public Snake extends Animal(){

@override
public int getTailLength(){
  return 10;
}
}

当我们声明想要getTailLenght()的实现时,编译器在抽象类中很好,我们还提到我们希望它抛出异常 - 但在上面的片段中已被省略。

我是否认为在使用接口和“实现”声明执行相同操作时不允许这样做?

我想因为你用@override注释方法,只要你有一个在ADT中强制执行的名称的方法,编译器就不关心你做什么了? 它会检查返回类型,为什么不强制执行异常?


This question already has an answer here:

I was wondering about the difference between using an abstract class and interface and this puzzled me a bit:

Suppose you have an abstract class

public abstract class Animal {   
//return the tail lenght of the animal
public abstract int getTailLength() throws IllegalStateException;
}

that promises that implementations of the abstract class have a method called getTailLength() [compiler forces extended classes to @override the abstract class and implement them] like so:

public Snake extends Animal(){

@override
public int getTailLength(){
  return 10;
}
}

The compiler is fine with this yet in the abstract class when we declare to want an implementation of getTailLenght() we also mention that we want it to throw an exception - yet in the above snippet that has been omitted.

Am I right in thinking that this is not allowed when doing the same with an Interface and 'implements' declaration?

I suppose that because you annotate the method with @override the compiler simply doesn't care what you do as long as you have a method that has the name you enforce in the ADT? It does check for the return type, why does it not enforce the exception?


原文:https://stackoverflow.com/questions/35634702
更新时间:2022-02-14 16:02

最满意答案

关于z轴的fadden旋转矩阵需要跟随正确的平移才能将其带回到屏幕上,可以这么说。 我在SurfaceTexture视频上测试了以下所有3个旋转:

旋转90

Matrix.rotateM(mTmpMatrix, 0, 90, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, 0, -1, 0);

旋转180

Matrix.rotateM(mTmpMatrix, 0, 180, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, -1, -1, 0);

旋转270

Matrix.rotateM(mTmpMatrix, 0, 270, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, -1, 0, 0);

fadden's rotation matrix about the z-axis needs to be followed by the correct translation to bring it back on-screen, so to speak. I've tested all 3 rotations below on SurfaceTexture video:

ROTATE 90

Matrix.rotateM(mTmpMatrix, 0, 90, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, 0, -1, 0);

ROTATE 180

Matrix.rotateM(mTmpMatrix, 0, 180, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, -1, -1, 0);

ROTATE 270

Matrix.rotateM(mTmpMatrix, 0, 270, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, -1, 0, 0);

相关问答

更多
  • mDirectVideo = new DirectVideo(texture); texture = createTexture(); 应该 texture = createTexture(); mDirectVideo = new DirectVideo(texture); 着色器 private final String vertexShaderCode = "attribute vec4 position;" + "attribute vec2 inputTextu ...
  • 您的列表不会为空,而是空列表,您可以根据第一个子列表进行模式匹配(假设Mat确保数据结构的一致性) rl [] = [] rl ([]:_) = [] rl m = map last m : (rl (map init m)) rl mat [[3,5,6],[2,4,0],[1,0,0]] 你错过了第二个例子。 Your list won't be empty but a list of empty lists, you can do the following to pattern match ba ...
  • t不旋转条目,它会沿对角线翻转: x <- matrix(1:9, 3) x ## [,1] [,2] [,3] ## [1,] 1 4 7 ## [2,] 2 5 8 ## [3,] 3 6 9 t(x) ## [,1] [,2] [,3] ## [1,] 1 2 3 ## [2,] 4 5 6 ## [3,] 7 8 9 R矩阵顺时针旋转90度: 您还需要在转置之前反转列: ...
  • 使用setRotate而不是preRotate setRotate将矩阵初始化为旋转矩阵 preRotate将当前矩阵乘以旋转矩阵M` = M×R 既然你从默认矩阵开始调用默认构造函数。 记住矩阵乘法不可交换。 use setRotate not preRotate setRotate initializes the matrix as a rotation matrix preRotate multiplies the current Matrix by a Rotation matrix M` = M ...
  • 假设矩阵R是围绕(x,y,z)轴旋转矩阵的角度a,则rotateM方法修改现有矩阵m,如下所示: m = R * m ,但setRotateM会覆盖它: m = R Let's say matrix R is rotation matrix around (x,y,z) axis by angle a, then rotateM method modifies existing matrix m like this: m = R * m, but setRotateM overwrites it: m = ...
  • 也许不是最优化的方式: pdl> $m = sequence(3,3)+1 pdl> p $m [ [1 2 3] [4 5 6] [7 8 9] ] pdl> p $m->transpose->slice( ':', '-1:0' ) [ [3 6 9] [2 5 8] [1 4 7] ] Perhaps not the most optimized way to do it: pdl> $m = sequence(3,3)+1 pdl> p $m [ [1 2 3] [4 5 ...
  • 你需要打破这个问题(提醒我来自gg和fb的面试问题): 首先解决一个序列一个单一的位置 然后解决旋转序列N次 将每个“圆圈”或环形模型化为一个数组。 您可能或可能不需要存储在单独的数据中 迭代每个环并应用旋转算法 让我们考虑需要旋转R时间的长度为L的数组的情况。 请注意,如果R是L的倍数,则数组将保持不变。 也要注意,向右旋转x次与向左旋转L - x相同(反之亦然)。 因此,您可以首先设计一种算法,能够左右旋转一个正好一个位置 减少向左旋转R次的问题,以将R modulo L向左旋转 如果你想进一步减少旋转 ...
  • 你想要的不是矩阵换位......而是差不多! :- use_module(library(clpfd)). matrix_rotated(Xss, Zss) :- transpose(Xss, Yss), maplist(reverse, Yss, Zss). 示例查询: ?- matrix_rotated([[a1,a2,a3,a4], [b1,b2,b3,b4], [c1,c2,c3,c4]], Xss). Xs ...
  • 3行使用xor运算符来交换值。 我永远不会使用它,除非你真的很难记忆,因为你明显注意到,这很难理解。 这是一个关于它用于交换值的算法的一些信息的链接 The 3 lines are using the xor operator to exchange values. I would never use it unless you really are hard pressed for memory because, as you obviously noticed, it's very hard to un ...
  • 关于z轴的fadden旋转矩阵需要跟随正确的平移才能将其带回到屏幕上,可以这么说。 我在SurfaceTexture视频上测试了以下所有3个旋转: 旋转90 Matrix.rotateM(mTmpMatrix, 0, 90, 0, 0, 1); Matrix.translateM(mTmpMatrix, 0, 0, -1, 0); 旋转180 Matrix.rotateM(mTmpMatrix, 0, 180, 0, 0, 1); Matrix.translateM(mTmpMatrix, 0, -1, ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)