我发现这个类在玉兰CMS源中使用了我不熟悉的类定义.任何知道如何使用以下代码样式的人都可以向我解释这究竟是什么吗?
在此代码示例中RenderingModel,RenderableDefinition它们都是接口.我知道我们不能在一个类中实现两个接口,但是这里通过其他方式实现.有人可以向我解释以下行中使用的技术,特别是:
public class RenderingModelImpl < RD extends RenderableDefinition >
implements RenderingModel {
Run Code Online (Sandbox Code Playgroud)
以下是您可以在magnolia java docs中找到的完整课程
public class RenderingModelImpl < RD
extends RenderableDefinition >
implements RenderingModel {
protected final RenderingModel parentModel;
protected final Content content;
protected final RD definition;
public RenderingModelImpl(Content content, RD definition, RenderingModel
parent) {
this.content = content;
this.definition = definition;
this.parentModel = parent;
}
public RenderingModel getParent() {
return this.parentModel;
}
public RenderingModel getRoot(){
RenderingModel model = this;
while(model.getParent() != null){ …Run Code Online (Sandbox Code Playgroud) 为什么必须覆盖接口的所有方法?
例如,如果我有
public class Foo extend JFrame implements ActionListener, KeyListener {
foo(){
}
@Override
public void keyPressed(KeyEvent arg) {
}
@Override
public void keyReleased(KeyEvent arg) {
}
@Override
public void keyTyped(KeyEvent arg) {
}
}
Run Code Online (Sandbox Code Playgroud)
我将有很多我甚至不会使用的方法,有没有办法删除未使用的已实现的方法,例如,如果我打算从接口使用一个方法
我也不想使用抽象,因为这意味着我无法创建对象的实例(至少我的编译器是这样说的)
我定义了以下类...
class Class2 implements ICommon {
....
ICommon wrappedClass;
//delegate interface methods to wrapped class
}
class Class1 implements ICommon {
//interface methods
//specific methods
public void method1() {
......
}
}
Run Code Online (Sandbox Code Playgroud)
我需要Class1覆盖method1()的Class2,但是我还是要实现的ICommon接口.有没有办法实现这一目标?
当我实现textwatcher时,会发生错误
Syntax error on token "implements", extends expected
Run Code Online (Sandbox Code Playgroud)
我的代码是
import android.text.TextWatcher;
public interface Testing implements TextWatcher{
}
Run Code Online (Sandbox Code Playgroud)
为什么我需要使用扩展?
我需要通过Enum用一些具体的方法来参数化我的类,例如:
class K<E extends Enum<E> implements SomeInterface>
Run Code Online (Sandbox Code Playgroud)
但Eclipse禁止我在"<>"中使用"implements"字样.我该怎么做才能解决我的问题?有没有明智的理由为什么我不能在泛型类型的定义中使用"implements"?
我正在使用Xamarin,我想创建一个实现GoogleMap.InfoWindowAdapter接口的CustomWindowAdapter.
到目前为止我试过这个:
public class CustomWindowAdapter : InfoWindowAdapter
{
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
错误CS0246:找不到类型或命名空间名称"InfoWindowAdapter"(您是否缺少using指令或程序集引用?)
以下是该界面的文档:https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.InfoWindowAdapter
我能帮忙吗?
我需要使用什么使用声明?
提前致谢
interface implements android-adapter xamarin google-maps-android-api-2
我有一个模拟狐狸和兔子的小型模拟器...我试图制作狐狸和兔子类来实现actor类,但是我收到了此错误消息,而且我不知道怎么了。
错误消息:Rabbit不是抽象的,并且不覆盖Actor中的抽象方法act(java.until.List)
兔子班
import java.util.List;
import java.util.Random;
public class Rabbit extends Animal implements Actor
{
// Characteristics shared by all rabbits (static fields).
// The age at which a rabbit can start to breed.
private static final int BREEDING_AGE = 5;
// The age to which a rabbit can live.
private static final int MAX_AGE = 40;
// The likelihood of a rabbit breeding.
private static final double BREEDING_PROBABILITY = 0.15;
// The maximum number of births.
private static final …Run Code Online (Sandbox Code Playgroud) 我有接口,抽象方法,并且有更多分类,并在下面使用这些引用类型。
public interface InterfaceA {
boolean mehod1();
boolean method2();
boolean newMethod(); //When added new method
}
public abstract class AbstractA implements InterfaceA{
// other common method
}
public Class C extend AbstractA //have to override three method
public Class D extend AbstractA //have to override three method
public Class E extend AbstractA //have to override three method but only should be override old method
public Class F extend AbstractA //have to override three method but only should be override old …Run Code Online (Sandbox Code Playgroud) 我想创建 2 个具有相同字段的枚举(甚至更多),以及与之相关的相同方法,例如:
enum Enum1 {
A1('A1', 1),
B1('B1', 2);
String name;
int x1;
Enum1(this.name, this.x1);
String concat(String s) {
return name + s;
}
}
enum Enum2 {
A2('A2', 3),
B2('B2', 4);
String name;
int x2;
Enum2(this.name, this.x2);
String concat(String s) {
return name + s;
}
}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能在不同的枚举中重用相同方法的代码?
name即,如何重用与concat上一个示例相关的代码?
我尝试使用一个类来实现两个枚举,但它不断提示我必须在每个枚举中分别重新实现方法concat和 getter name。
我失败的尝试是这样的:
class Reuse {
String name;
String concat(String s) {
return name + s;
}
}
enum Enum1 implements Reuse …Run Code Online (Sandbox Code Playgroud) 注意:我发现本文在实现期间无法在打字稿中找到OnInit,但是下面的代码已经导入了OnInit/ OnDestroy。
我发现的所有示例(例如,使用Route Parameters)都指示在类定义中添加implements OnInit/ OnDestroy子句,并在预订时从路由中获取参数时包括了ngOnInit/ ngOnDestroy方法-代码正在执行此操作。
但是,VS2017报告该子句错误“错误地实现OnInit / OnDestroy”,并报告该函数错误“无法找到ngOnInit / ngOnDestroy”。
如果删除该implements子句并注释ngOnInit/ ngOnDestroy函数(仅将代码保留在的主体中ngOnInit),则该代码有效;成功从路由参数中获取参数。
import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
import { Http } from '@angular/http';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'submission',
templateUrl: './submission.component.html'
})
export class SubmissionComponent implements OnInit, OnDestroy {
private baseUrl: string;
private http: Http;
private route: ActivatedRoute;
private sub: any; …Run Code Online (Sandbox Code Playgroud) implements ×10
java ×6
extends ×3
interface ×3
methods ×2
abstract ×1
android ×1
angular ×1
class ×1
code-reuse ×1
dart ×1
enums ×1
generics ×1
inheritance ×1
ngondestroy ×1
ngoninit ×1
overriding ×1
types ×1
xamarin ×1