【java – 如何使用Spring在枚举构造函数中注入参数?】教程文章相关的互联网学习教程文章

java复制构造函数和继承【代码】

经过一番搜索,我没有找到有关复制构造函数和继承的任何好答案.我有两个班:用户和学员.受训者从User继承,并且两个String参数被添加到受训者.现在,我设法制作了User的副本构造函数,但对Trainee的副本构造函数不满意.用户复制构造函数的代码如下:public User (User clone) {this(clone.getId(), clone.getCivilite(),clone.getNom(), clone.getPrenom(), clone.getEmail(), clone.getLogin(), clone.getTel(), clone.getPortable(),...

java-传递null时选择哪个构造函数?【代码】

在下面的示例中,我有2个构造函数:一个构造函数使用String,另一个构造函数使用自定义对象.在此自定义对象上,存在方法“ getId()”,该方法返回String.public class ConstructorTest {private String property;public ConstructorTest(AnObject property) {this.property = property.getId();}public ConstructorTest(String property) {this.property = property;}public String getQueryString() {return "IN_FOLDER('" + property...

java-模拟与嘲笑的构造函数【代码】

我想将构造函数模拟为方法.public String generaID() { GeneraIDParaEntidadCliente aux = new GeneraIDParaEntidadCliente(nombre, registro); entidad.setID(aux.generaID); }在我的测试中,我想做这样的事情:when(new GeneraIDParaEntidadCliente(anyString(), any(Entidad.class)).thenReturn(generaIdMock) 但是给我这个错误org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 知道为什么吗?解决方法...

java构造函数:this(.)【代码】

为什么输出为“ 021”?为什么有“ 0”和“ 1”(因为“ i”得到“ 2”,为什么它变为“ 1”)?public class C {protected int i;public C(int i){this(i,i);System.out.print(this.i);this.i=i; }public C(int i, int j) {System.out.print(this.i);this.i=i+j; }public C(){this(1);System.out.print(i); }public static void main(String[] args) {C c=new C(); }}解决方法:C()调用C(1),后者调用C(1,1) > C(1,1)打印0(this.i的默认...

java – 为什么我需要在这里显式编写构造函数?【代码】

这就是我遇到问题的方法.我举个例子:package check;public class Check {int a,b;Check (int i,int j) {a = i;b = j;} }这可以.现在我想通过扩展Check来创建一个子类.所以我写道:class V extends Check {}我写完后,在Eclipse中出现了一个十字架,单击它我发现了一条消息:implicit super constructor Check() is undefined for default constructor. Must define an explicit constructor.我用Google搜索了问题并添加了V (int i, ...

为什么在泛型类(Java)的构造函数中提供类型参数是错误的?【代码】

我只是从教科书中学习Java中的泛型,它讲的是GenericStack< E>类.用ArrayList< E>实现. 因为为了创建一个字符串堆栈,您可以使用GenericStack<String> = new GenericStack<String>()要么GenericStack<String> new GenericStack<>()因此不应该是构造函数GenericStack被定义为public GenericStack< E>(),还是public GenericStack<>()?答案是不.它应该被定义为public GenericStack(). 为什么是这样?显然,构造函数可以很容易地从类声明...

java – 带有Comparator <?>参数的TreeSet构造函数【代码】

在Java的类TreeSet文档中,其中一个构造函数显示为具有以下标题:TreeSet(Comparator<? super E> c)有人可以帮助解释为什么TreeSet的构造函数将比较器对象作为其参数吗?我不知道为什么要这样做.解决方法:TreeSet中的元素保持排序. 如果使用没有Comparator的构造函数,则元素类的自然顺序(由Comparable的实现定义)将用于对TreeSet的元素进行排序. 如果需要不同的顺序,可以在构造函数中提供Comparator.

java.lang.Exception:自定义运行器类AndroidJUnit4应该有一个带有签名AndroidJUnit4的公共构造函数(Class testClass)【代码】

gradle看起来像:apply plugin: 'com.android.application'android {compileSdkVersion 25buildToolsVersion "25.0.2"defaultConfig {applicationId "com.google.developer.taskmaker"minSdkVersion 19targetSdkVersion 25versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-an...

java – typescript enum上的构造函数?【代码】

我们的代码目前有一种情况,我们在Java层中使用Enums,它使用如下构造函数存储id和’display value’:public enum Status implements EnumIdentity {Active(1, "Active"),AwaitingReview(2, "Awaiting Review"),Closed(3, "Closed"),Complete(4, "Complete"),Draft(5, "Draft"),InProcess(6, "In Process"),InReview(7, "In Review"),NotStarted(8, "Not Started"),PendingResolution(9, "Pending Resolution"),Rejected(10, "Rejec...

java – 已弃用PageRequest构造函数【代码】

我正在使用Spring Data Commons v2快照,我发现PageRequest的构造函数已被弃用.这似乎发生在M1和之间. M2.不幸的是,这是Pageable接口的唯一[实际]实现.我想知道努力的方向,以及当前发展的更好选择.解决方法:它只是被弃用的构造函数.代替new PageRequest(firstResult, maxResults, new Sort(...))你现在可以使用了PageRequest.of(firstResult, maxResults, Sort.by(...))就是这样.

在java中使用参数化构造函数有什么用?【代码】

我是java的初学者,我想以简单的方式知道为什么你应该使用参数化构造函数而不是编译器提供的默认构造函数. 谢谢解决方法:通过默认构造函数,您的对象可能具有的任何属性都设置为0,false等等.如果要立即设置属性,可以使用参数化构造函数.当然,使用自己的构造函数也可以在创建对象(技术上为while)之前执行代码. 顺便说一句:“默认不会为属性设置任何值”的答案是错误的.例如这段代码:public class Test {private int test;private bo...

java – 构造函数和getter以及setter之间的区别【代码】

我一直在做大学项目的任务.有一点,当你真正使用构造函数方法来实现相同的结果时,我对getter和setter的实际使用感到困惑.我搜索过并找到了很多答案,但不能令人满意的解释.我有laptop.java如下public class laptop {private String model;public laptop(String brand){model=brand;}public String toString(){return "Laptop Brand is: "+ model;} }和调用构造函数的laoptopRecords.javapublic class laptopRecords {public static v...

java – 如何将参数注入TestNG类的构造函数?【代码】

我已经实现了一个带有策略模式的程序.所以我有一个在某些地方使用的接口,可以替换具体的实现. 现在我想测试这个程序.我想以类似的方式做到这一点.编写一次测试,测试接口.应在测试开始时注入具体的接口实现,以便我可以轻松替换它. 我的testclass看起来类似于这个:public class MyTestClass {private StrategeyInterface strategy;public MyTestClass(StrategeyInterface strategy) {this.strategy = strategy;}....test methods us...

java – 在Android上的ListFragment中使用ArrayAdapter获取构造函数错误【代码】

这是我的代码.我收到错误ArraryAdapter上的构造函数ArrayAdapter< String>(MainFragment,int,String [])未定义. 如何使用数组项填充listView1?public class MainFragment extends ListFragment { String[] items = { "12 Monkeys", "(500) Days of Summer", "Chariots of Fire" };@Overridepublic void onCreate(Bundle savedInstanceState) {setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_ite...

java – Android – 活动构造函数【代码】

我注意到使用快捷键Alt Insert并选择构建器,它尝试使用每个私有属性(例如cManager和mTextView)创建构造函数.我记得我已经创建了没有它的项目并且工作正常. 在完整的logcat和Activity构造函数之后运行应用程序时发生错误: 具有私有财产的构造函数:private ConnectivityManager cManager; private TextView mTextView;public SplashScreenActivity() {this.cManager = (ConnectivityManager) this.getSystemService(Context.CONNEC...

构造函数 - 相关标签