在下面的测试中,TesterClass对其两个类型参数之间的关系设置了约束.方法func2()似乎打破了这个约束,我希望它会在某处导致类型编译错误(在func2的定义中,或者每当类与String之外的任何第二个参数一起使用时),但它不会!
此外,如果我调用func2并将结果保存在适当类型的变量中,则编译失败(在该变量的类型上).但是做同样的事情并保存在更通用的类型(例如Object)中会成功,尽管事实上函数的返回类型在两种情况下都应该具有相同的类型(在向上转换之前).
这里发生了什么?
谢谢!
public class TestGenerics {
public static class ParamedType<T> {}
public class TesterClass<A extends ParamedType<B>, B> {
public TesterClass<A, B> func() {
return new TesterClass<A, B>();
}
public TesterClass<A, String> func2() {
return new TesterClass<A, String>();
}
}
public Object test() {
// How can I use these type parameters? Doesn't .func2 now have an invalid return type?
TesterClass<ParamedType<Integer>,Integer> testClass = new TesterClass<TestGenerics.ParamedType<Integer>, Integer>();
//TesterClass<ParamedType<String>, Integer> res2 = testClass.func2(); // <-- will not compile
Object res = …
Run Code Online (Sandbox Code Playgroud) 我在as3中几乎是新手,我带来了一个双重声明,声明'如果'吼叫,做同样的想法?
public function get products(a:Object){
if(a){
// smtg
}
if(null!=a){
// smtg
}
}
Run Code Online (Sandbox Code Playgroud) 即使它调用超类构造函数,我也无法弄清楚如何编译我的子类?
这是不能编译的类:
package departments;
import employees.*;
public class DepartmentEmployee extends Employee{
private Department department;
public DepartmentEmployee(Profile profile, Address address, Occupation occupation, Department department) {
assert (department != null) : "invalid Department";
super(profile, address, occupation);
this.department = department;
}
}
Run Code Online (Sandbox Code Playgroud)
这是超类:
package employees;
public class Employee {
protected Profile profile;
protected Address address;
protected Occupation occupation;
protected Employee(Profile profile, Address address, Occupation occupation) {
assert (profile != null) : "invalid Profile";
assert (address != null) : "invalid Address";
assert (occupation != …
Run Code Online (Sandbox Code Playgroud) 在我的文件系统中搜索文件时,我的程序抛出了空指针异常,因为File.list()无法访问我的文件系统上的"Documents And Settings"并尝试解析String [] myArray = File.list() myArray为null抛出了异常.
如何检查文件或文件夹是否无法使用文件访问并保持不发生?
MySQL数据类型中的TinyInt/SmallInt/MediumInt/Int/BigInt之间的区别?
我想使用11个长度的[unsigned]整数字段,我应该使用什么?
[我正在使用PHPMyAdmin]
我正在关注一个教程,在设置完所有内容后,我得到了:
致命错误:未捕获异常'SmartyException',消息'请使用parent :: __ construct()来调用父constuctor'
这是我的配置文件:
<?php
// SITE_ROOT contains the full path to the tshirtshop folder
define('SITE_ROOT', dirname(dirname(__FILE__)));
// Application directories
define('PRESENTATION_DIR', SITE_ROOT . '/presentation/');
define('BUSINESS_DIR', SITE_ROOT . '/business/');
// Settings needed to configure the Smarty template engine
define('SMARTY_DIR', SITE_ROOT . '/libs/smarty/');
define('TEMPLATE_DIR', PRESENTATION_DIR . 'templates');
define('COMPILE_DIR', PRESENTATION_DIR . 'templates_c');
define('CONFIG_DIR', SITE_ROOT . '/include/configs');
?>
Run Code Online (Sandbox Code Playgroud)
我的目录结构是:
mydomain.com/test/include
mydomain.com/test/libs
mydomain.com/test/presentation
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
我使用Mercurial从谷歌代码克隆了一个android项目,但没有.classpath或.project文件,因此eclipse甚至不能将代码识别为项目.
有谁知道是否有一个简单的方法将这个项目导入eclipse?
(我在想,也许我可以从其他项目编辑这些文件并将它们复制到这个项目中,但我对这些文件的目的不太了解).
我通常通过以下方式生成随机内容:
Random random = new Random(DateTime.Now.Millisecond);
for (int i = 0; i < 100; i++)
{
Console.WriteLine(random.Next(0, 100));
}
Run Code Online (Sandbox Code Playgroud)
我想知道如果我将随机实例化放在循环中是否有区别:
for (int i = 0; i < 100; i++)
{
Random random = new Random(DateTime.Now.Millisecond);
Console.WriteLine(random.Next(0, 100));
}
Run Code Online (Sandbox Code Playgroud)
哪个更随机,或者它们是相同的?
在下面的代码我输出像(最后一个给出分段错误)
U
s
HelloThisisatest
Segmentation fault (core dumped)
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么.代码是
int main()
{
char *a[]={"Hello" "This" "is" "a" "test"};
printf("%c\n",a[1][0]);
printf("%c\n",a[0][8]);
printf("%s\n",a[0]);
printf("%s\n",a[3]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
另一个问题是我们可以在不使用逗号的情况下初始化二维数组吗?当我用\n
s 替换\t
s然后输出变化时,我得到的另一种情况
"你的HelloThisisatest(null)"
为什么?
我有一个Maven项目,它针对数据库运行一些测试.我可以使用这些测试,mvn clean verify
但我想指定一些数据库属性,例如.数据库名称,端口名称等...在我的pom.xml文件中,我可以在Java中使用它来创建数据库连接.
我已将此添加到我的POM中,
<properties>
<server>localhost</server>
<database>mydatabase</database>
<port>1433</port>
</properties>
Run Code Online (Sandbox Code Playgroud)
我可以从我的Java代码中访问这些属性,还是需要创建一个Maven插件并将这些属性作为参数传递给我的插件并clean verify
从我的自定义插件调用?