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);

相关问答

更多

使用SurfaceTexture和OpenGL修改相机输出(Modifying camera output using SurfaceTexture and OpenGL)

mDirectVideo = new DirectVideo(texture); texture = createTexture(); 应该 texture = createTexture(); mDirectVideo = new DirectVideo(texture); 着色器 private final String vertexShaderCode = "attribute vec4 position;" + "attribute vec2 input...

在Haskell中旋转矩阵(Rotate a matrix in Haskell)

您的列表不会为空,而是空列表,您可以根据第一个子列表进行模式匹配(假设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 mat...

在R中旋转矩阵(Rotate a Matrix in R)

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)

使用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`...

Matrix.setRotateM和Matrix.rotateM之间有什么区别吗?(Is there any difference between Matrix.setRotateM and Matrix.rotateM)

假设矩阵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:...

使用Perl PDL旋转矩阵(Use Perl PDL to rotate a matrix)

也许不是最优化的方式: 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] ...

旋转矩阵n次(Rotate a matrix n times)

你需要打破这个问题(提醒我来自gg和fb的面试问题): 首先解决一个序列一个单一的位置 然后解决旋转序列N次 将每个“圆圈”或环形模型化为一个数组。 您可能或可能不需要存储在单独的数据中 迭代每个环并应用旋转算法 让我们考虑需要旋转R时间的长度为L的数组的情况。 请注意,如果R是L的倍数,则数组将保持不变。 也要注意,向右旋转x次与向左旋转L - x相同(反之亦然)。 因此,您可以首先设计一种算法,能够左右旋转一个正好一个位置 减少向左旋转R次的问题,以将R modulo L向左旋转 如果你想进一...

在Prolog中旋转矩阵(Rotate a matrix in Prolog)

你想要的不是矩阵换位......而是差不多! :- 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...

在Java中旋转矩阵混淆(Rotate matrix confusion in Java)

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 ...

使用Matrix的rotateM()从SurfaceTexture旋转矩阵但损坏视频输出(Use rotateM() of Matrix to rotate matrix from SurfaceTexture but corrupt the video output)

关于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,...

相关文章

更多

研磨设计模式之抽象工厂模式(Abstract Factory)-场景问题

举个生活中常见的例子——组装电脑,我们在组装电脑的时候,通常需要选择一系列的配件,比如:CPU、硬盘、 ...

Java泛型父类取得子类的泛型参数T的Class类型

import java.lang.reflect.ParameterizedType;import j ...

java反射详解(一)_Class类

Java类用于描述一类事物的共性,该类事物有什么属性,没有什么属性,至于这个属性的值是什么,则是由这个 ...

如何卸载assembly?或者class

.net的动态编译功能很好,但是有个问题,动态编译的代码,每次执行后,都会产生一个新的assembly ...

mybatis There is no getter for property named 'xx' in 'class java.lang.String

用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no get ...

ssh 框架下 class 类打包发布

ssh 框架下 class 类打包后放到 web-inf/lib 下后 @autowire自动注入似乎 ...

【原】storm源码之一个class解决nimbus单点问题

一、storm nimbus 单节点问题概述 1、storm集群在生产环境部署之后,通常会是如下的结构 ...

Java 异常处理

Java 异常处理 异常是程序中的一些错误,但并不是所有的错误都是异常,并且错误有时候是可以避免 ...

Java 接口

Java 接口 接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽 ...

关于java直接可执行的问题

想写一个追女生的程序,怎么把在对方电脑上双击直接执行? 问题补充:非常谢谢,一直都没有搞懂这个 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本