问题标签 [parameterized-constructor]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
9 回答
10909 浏览

java - Any way to call the default constructor from a parameterized constructor?

Suppose, I have the following code

I would like to know, Is there any way, I can call the main(default) constructor from the parametrized constructor (i.e. C(int i, String s) in this case) ?

Or I have just copy-paste the entire contents from the main(default) constructor to the parametrized one, as shown in comments in the above code?

Note

I need to call the default constructor after the variables i and s are set in the parametrized constructor, as the processing involves these variables.

Edit

I see this post, which says placing this() as the first line would call the default constructor. But I need to call it after the setting of values.

0 投票
1 回答
781 浏览

jsf-2 - 我的 h:inputText 值在绑定到从 HashMap 收集的参数化类的某个实例的字段时未验证?

我正在尝试做一些“自定义轻量级”JSF 组件绑定。在我的bean(控制一些JSF页面)中,我声明了一个HahsMap,其中跨越我的h:inputTextid(出现在页面中)的键将这些id映射到自定义HInputText<T>对象(T在下面给出的示例中是Long)。然后我使用HInputText<T>对象来保存相应 h:inputText 属性的子集:value应该是类型T, rendered,required等。在这个方向上,来自HInputText<T>对象的字段为属性赋予值h:inputText

我的问题是,当在h:inputText内部使用这样的 a时h:form,不会发生 JSF 验证:我可以在h:inputText(应该包含 Long 值)中键入字母数字字符,并且我的表单提交时不会显示任何错误。请注意,required属性rendered管理正确(因为required设置为 true,所以当我将该h:inputText字段留空时出现错误),并且当我尝试h:inputText使用一些h:outputText字母数字字符显示页面中的值时。

是否有一些技巧可以使 JSF 验证工作而不必为每个显式定义自定义验证器h:inputText

HInputText.class:

我的托管 Bean 中的代码片段:

最后是我的 jsf 页面的一个片段:

0 投票
2 回答
202 浏览

ocaml - OCaml 中的参数化类型

我已经搜索了一段时间,但找不到解决方案。这可能是一个我无法弄清楚的简单语法问题。

我有一个类型:

我想创建一个类型的变量string string sum

我尝试了不同的方式在类型参数周围加上括号,我得到了几乎相同的错误。

但是,它适用于单个参数类型,所以我想有一些我不知道的语法。

有人可以告诉我如何使用两个参数来做到这一点吗?

0 投票
3 回答
2711 浏览

java - Nested class cannot be cast to java.lang.reflect.ParameterizedType

I am trying to implement model structure like this:

Unfortunatelly I am getting runtime error when I am trying to create object of TplInsuranceDoctor, wich is nested class:

That errors points to Generic contructor:

Here are model classes:


Here is The way I create object:


I understand That I should somehow parametrise type of nested class TplInsuranceDoctor, but I dont know how. Everything I've tried fail compilation. Please help

0 投票
3 回答
295 浏览

c++ - 如何在 C++ 中将参数化构造函数初始化为默认构造函数?

如何在 C++ 中将参数化构造函数初始化为默认构造函数?这个问题在我的考试中被问到。我们得到了一个参数化的构造函数,它也可以作为默认构造函数。

0 投票
3 回答
286 浏览

c++ - C++ 参数化构造函数

我想知道参数化构造函数是否应该总是只有实际初始化类属性的参数。例如,在调用:

如果我不需要存储文件路径怎么办?

0 投票
1 回答
130 浏览

types - 如何在 Julia 实例化期间更改参数类型

我正在尝试执行以下操作

其中函数changeType将类型参数更改为其他类型。它不一定是一个函数,我很高兴使用字典或宏或 w/e,我只需要一种方法来做到这一点。

我用函数和字典都试过了,都导致了错误。

0 投票
1 回答
74 浏览

java - 编译参数化构造器代码期间的 Eclipse 错误

当我编写一个简单的参数化构造函数程序时,它会在命令行中编译和运行。

但是,当它在 Eclipse IDE 中执行时,我收到以下异常:

线程“main”中的异常 java.lang.NoSuchMethodError: a_constructor.Test.(II)V at a_constructor.ParametrizedConstructor.main(ParametrizedConstructor.java:15)。

代码 :

0 投票
2 回答
67 浏览

java - 实例化参数化类

只是想知道这是否是正确的方法。我想构造我的参数化类的实例,其中一个实例变量是泛型类型。下面的代码有效,但我在主方法中收到很多警告“SomeObject 是原始类型。对泛型类型 SomeObject 的引用应该被参数化”。

}

0 投票
1 回答
90 浏览

c++ - 为什么不调用构造函数?

在下面的代码中,我有两个参数化构造函数。我已经编译并运行到Gcc编译器,但没有调用构造函数。

输出:

那么,为什么不调用构造函数呢?