我希望从编译时间以及运行时方面来看.getClass(),提供正确类型的返回值不是问题.
但我一定是错的.
public class _GetClassGenerics2 {
static class MyClass {
}
public static void main(String[] args) {
MyClass myInstance = new MyClass();
// here it works
Class<? extends MyClass> type = myInstance.getClass();
myMethod(myInstance);
}
public static <T extends MyClass> void myMethod(T instance) {
Class<? extends T> type = instance.getClass();
// java.lang.RuntimeException: Uncompilable source code - incompatible types
// required: java.lang.Class<? extends T>
// found: java.lang.Class<capture#1 of ? extends _GetClassGenerics2.MyClass>
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:它不工作Class<T>,并Class<? super T> …
我有几个IP地址,如:
115.42.150.37115.42.150.38115.42.150.50如果我想搜索所有3个ip地址,我应该写什么类型的正则表达式?例如,如果我这样做115.42.150.*(我将能够搜索所有3个IP地址)
我现在能做的就是:/[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}/但似乎效果不好.
谢谢.
系统信息:我在2个月大的笔记本电脑上运行64位Ubuntu 10.10.
大家好,我对C中的fork()函数有疑问.从我正在使用的资源(Stevens/Rago,YoLinux和Opengroup)我理解当你分叉一个进程时,父进程和子进程从下一个命令继续执行.由于fork()将0返回给子节点,并将子节点的进程id返回给父节点,因此可以使用两个if语句来分散它们的行为,一个if(pid = 0)表示子节点,if(pid> 0),假设你用pid = fork()分叉.
现在,我发生了最奇怪的事情.在我的main函数的开头,我打印到stdout已经分配给变量的几个命令行参数.这是整个程序中的第一个非赋值语句,但有时当我稍后在程序中调用fork时,会执行此print语句.
我的程序的目标是创建一个"进程树",每个进程有两个子进程,深度为3,从而创建初始可执行文件的14个子进程.每个进程在fork之前和之后打印其父进程ID及其进程ID.
我的代码如下并且被正确评论,命令行参数应该是"ofile 3 2 -p"(我还没有实现-p/-c标志):
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
if(argc != 5)//checks for correct amount of arguments
{
return 0;
}
FILE * ofile;//file to write to
pid_t pid = 1;//holds child process id
int depth = atoi(argv[2]);//depth of the process tree
int arity = atoi(argv[3]);//number of children each process should have
printf("%d%d", depth, arity);
ofile = fopen(argv[1], "w+");//opens specified file for …Run Code Online (Sandbox Code Playgroud) 你如何只过滤字符串的数字?
Example Pseudo Code:
number = $("thumb32").filternumbers()
number = 32
Run Code Online (Sandbox Code Playgroud) 这里我基于一个问题..我有两个相同格式的时间戳(2010年12月14日18:23:19和2010年12月14日星期二17:23:19).我怎样才能在几小时内得到两个时间戳的差异.请帮我
我知道从API级别5可以在意图中指定一个标志,以防止在我开始新活动时应用正常动画:
myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
Run Code Online (Sandbox Code Playgroud)
但是,我的问题是:有没有办法在支持Android 1.6的应用程序中实现相同的功能?
我有以下表格:
table A:
FOO (PK) | CLIENT (PK)
table B:
BAR (PK) | CLIENT (PK/FK) | FOO (FK)
Run Code Online (Sandbox Code Playgroud)
PK - >主键
FK - >外键
A和B之间存在一对多关系.我不能简单地这样做:
class AMap
{
public AMap()
{
CompositeId().KeyReference(a => a.FOO)
.KeyReference(a => a.CLIENT);
HasMany(a => a.B);
}
}
class BMap
{
public BMap()
{
CompositeId().KeyReference(a => a.BAR)
.KeyReference(a => a.CLIENT);
References(a => a.A);
}
}
Run Code Online (Sandbox Code Playgroud)
它将失败,但有以下异常:
外键(FKE7804EB3DA7EBD4B:B [FOO]))必须与引用的主键具有相同的列数(A [FOO,CLIENT])
是否可以使用流畅的nhibernate正确映射?
将LINQ-Query结果转换为新结果的最佳做法是什么DataTable?
我能找到比foreach每个结果项更好的解决方案吗?
编辑 AnonymousType
var rslt = from eisd in empsQuery
join eng in getAllEmployees()
on eisd.EMPLOYID.Trim() equals eng.EMPLOYID.Trim()
select new
{
eisd.CompanyID,
eisd.DIRECTID,
eisd.EMPLOYID,
eisd.INACTIVE,
eisd.LEVEL,
eng.EnglishName
};
Run Code Online (Sandbox Code Playgroud)
编辑2: 我有例外:
除Contains()运算符外,本地序列不能用于查询运算符的LINQ to SQL实现.
当我尝试执行查询并在此处找到解决方案时IEnumerable.Except不会工作,所以我该怎么办?
并需要linq的帮助
谷歌浏览器发送多个请求以获取页面,这显然不是一个错误,而是一个功能.我们作为开发人员必须处理它.
至于我可以在五分钟内挖出来,chrome就是为了让冲浪更快,所以如果一个连接丢失,第二个将接管.
我想如果网站发展得很好,那么它的功能就不会受到影响,因为多个请求并不是新的.
但我只是不确定我是否已考虑到此功能可以产生的所有情况.
会有什么特殊情况吗?有什么最好的做法来处理它们吗?
更新1:现在我明白为什么当我用chrome打开页面时,我的银行页面会出错!它说:"只有一个浏览器窗口应该打开." 那是他们解决安全威胁的方法吗?!!
在python 2.6.6中,我如何捕获异常的错误消息.
IE:
response_dict = {} # contains info to response under a django view.
try:
plan.save()
response_dict.update({'plan_id': plan.id})
except IntegrityError, e: #contains my own custom exception raising with custom messages.
response_dict.update({'error': e})
return HttpResponse(json.dumps(response_dict), mimetype="application/json")
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.我明白了:
IntegrityError('Conflicts are not allowed.',) is not JSON serializable
Run Code Online (Sandbox Code Playgroud)