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);
相关问答
更多使用SurfaceTexture和OpenGL修改相机输出(Modifying camera output using SurfaceTexture and OpenGL)
在Haskell中旋转矩阵(Rotate a matrix in Haskell)
在R中旋转矩阵(Rotate a Matrix in R)
Android旋转矩阵(Android Rotate Matrix)
Matrix.setRotateM和Matrix.rotateM之间有什么区别吗?(Is there any difference between Matrix.setRotateM and Matrix.rotateM)
使用Perl PDL旋转矩阵(Use Perl PDL to rotate a matrix)
旋转矩阵n次(Rotate a matrix n times)
在Prolog中旋转矩阵(Rotate a matrix in Prolog)
在Java中旋转矩阵混淆(Rotate matrix confusion in Java)
使用Matrix的rotateM()从SurfaceTexture旋转矩阵但损坏视频输出(Use rotateM() of Matrix to rotate matrix from SurfaceTexture but corrupt the video output)
相关文章
更多研磨设计模式之抽象工厂模式(Abstract Factory)-场景问题
Java泛型父类取得子类的泛型参数T的Class类型
java反射详解(一)_Class类
如何卸载assembly?或者class
mybatis There is no getter for property named 'xx' in 'class java.lang.String
ssh 框架下 class 类打包发布
【原】storm源码之一个class解决nimbus单点问题
Java 异常处理
Java 接口
关于java直接可执行的问题
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!