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:
- Java abstract classes which throw 4 answers
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
最满意答案
关于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 ...
-
在Haskell中旋转矩阵(Rotate a matrix in Haskell)[2023-02-20]
您的列表不会为空,而是空列表,您可以根据第一个子列表进行模式匹配(假设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 ... -
在R中旋转矩阵(Rotate a Matrix in R)[2023-10-25]
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度: 您还需要在转置之前反转列: ... -
Android旋转矩阵(Android Rotate Matrix)[2021-09-22]
使用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 = ...
-
使用Perl PDL旋转矩阵(Use Perl PDL to rotate a matrix)[2023-06-06]
也许不是最优化的方式: 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 ... -
旋转矩阵n次(Rotate a matrix n times)[2023-04-28]
你需要打破这个问题(提醒我来自gg和fb的面试问题): 首先解决一个序列一个单一的位置 然后解决旋转序列N次 将每个“圆圈”或环形模型化为一个数组。 您可能或可能不需要存储在单独的数据中 迭代每个环并应用旋转算法 让我们考虑需要旋转R时间的长度为L的数组的情况。 请注意,如果R是L的倍数,则数组将保持不变。 也要注意,向右旋转x次与向左旋转L - x相同(反之亦然)。 因此,您可以首先设计一种算法,能够左右旋转一个正好一个位置 减少向左旋转R次的问题,以将R modulo L向左旋转 如果你想进一步减少旋转 ... -
在Prolog中旋转矩阵(Rotate a matrix in Prolog)[2022-07-15]
你想要的不是矩阵换位......而是差不多! :- 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 ... -
在Java中旋转矩阵混淆(Rotate matrix confusion in Java)[2021-09-30]
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, ...