所以我在Java中有以下内容:
private List<SomeType>variable;
// ....variable is instantiated as so ...
variable = new ArrayList<SomeType>();
// there's also a getter
public List<SomeType> getVariable() { /* code */ }
Run Code Online (Sandbox Code Playgroud)
我希望能够做到的是弄清楚这variable是一个以SomeType编程方式的集合 .我在这里读到我可以从方法中确定,getVariable()但有没有办法直接告诉我variable?
我已经能够SomeType根据链接中的信息从getter方法中检索.我也成功地检索了周围班级的所有领域,SurroundingClass.getClass().getDeclaredFields()但这并没有告诉我它是List<SomeType>.
编辑:根据bmargulies的反应做以下将实现我想要的:
Field[] fields = SurroundingClass.getDeclaredFields();
/* assuming it is in fields[0] and is a ParameterizedType */
ParameterizedType pt = (ParameterizedType) fields[0].getGenericType();
Type[] types = pt.getActualTypeArguments();
/* from types I'm able to see the information …Run Code Online (Sandbox Code Playgroud) 对于Ex You date,在文本框中输入各种表单
并且输出是三个文本框首先是日期显示= 12文本框第二个是月份显示= augest文本框第三个是年份显示= 2010
我是编程新手,但努力工作并弄清楚为什么我会遇到上述错误.我已经阅读并尝试了我在网上找到的所有内容,该程序来自Head First iPhone开发手册第7章(他们的论坛没有解决这个错误,并且该论坛上的一些问题都得到了解答).
我已经尝试过或确认过:
在应用程序目标中检查目标(我的意思是主应用程序名称是唯一显示并且被检查为目标的应用程序名称)
我试过更改模拟器和sdk的版本
我添加了它正在寻找的类的#import(我的代码完全是书籍)
我的直觉告诉我这是IB的内容,但没有帖子暗示可能是问题(可能是错误的东西?)
任何帮助将不胜感激!!
更新:
CoreData框架就在那里 - 没有错过.谢谢你,还有其他想法吗?
很抱歉在"答案"中发帖,只有选项可用(在创建帐户之前写入和发布的问题 - 抱歉是laaaamo)
这是完整的错误:
Ld build/Debug-iphonesimulator/iBountyHunter.app/iBountyHunter normal i386
cd /Users/Home/Desktop/iBountyHunter
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk -L/Users/Home/Desktop/iBountyHunter/build/Debug-iphonesimulator -F/Users/Home/Desktop/iBountyHunter/build/Debug-iphonesimulator -filelist /Users/Home/Desktop/iBountyHunter/build/iBountyHunter.build/Debug-iphonesimulator/iBountyHunter.build/Objects-normal/i386/iBountyHunter.LinkFileList -mmacosx-version-min=10.5 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework CoreData -o /Users/Home/Desktop/iBountyHunter/build/Debug-iphonesimulator/iBountyHunter.app/iBountyHunter
Undefined symbols:
"_OBJC_CLASS_$_FugitiveDetailViewController", referenced from:
objc-class-ref-to-FugitiveDetailViewController in FugitiveListViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
思考?非常感谢你的帮助!
我有以下问题:
在代码中使用状态的首选方法是什么?枚举OR单例?
我在DB中存储了状态值及其ID.如果de DB中的状态更改,则代码中还需要进行一些更改.
根据惯例,现在有人更喜欢什么?
我一直在网上看,但找不到明确的答案.
我有一个名为EmailMessage的对象,它有一个可以为空的System.DateTime字段,名为Timestamp.在我的C#代码中,我有以下几行:
var TS = EmailMessage.Timestamp == null ? System.DateTime.Now : EmailMessage.Timestamp;
Run Code Online (Sandbox Code Playgroud)
为什么.NET 4推断TS的数据类型是System.DateTime?而不是System.DateTime(换句话说,为什么.NET 4认为TS可以为空?)对我而言,TS显然是不可空的.
在此先感谢您的帮助.
在.ascx上编写C#代码时,我很无聊,使用这种语法:
<%
foreach (OriginalPackage.MyPack in OriginalPackage.MyPacks) {
}
%>
Run Code Online (Sandbox Code Playgroud)
代替
foreach (MyPack in MyPacks) {
}
Run Code Online (Sandbox Code Playgroud)
写下正确的 using OriginalPackage;
那么,有没有办法using在.ascx上使用?
有许多解决方案可用于将列表转换为DataTable使用反射的列表,这可用于转换匿名类型.但是,它有很多匿名类型的列表,然后性能可能是一个问题.
这是DataTable从列表中创建一个的唯一方法吗?有更快的方法吗?
我们一直在使用协议缓冲区,并使用protoc生成c ++和python文件,使用protobuf-csharp-port生成c#文件.目前这些是单独完成的,来自linux的c ++和python以及来自windows的c#.我们希望有一个脚本生成所有这些,在linux中运行.
要做到这一点,我试图用单声道运行ProtoGen.exe,但它不会产生任何输出.运行以下命令,但不生成cs文件,也没有错误.
mono ../cs/Packages/Google.ProtocolBuffers/tools/ProtoGen.exe --protoc_dir=/usr/local/bin/ ./subdir/simple_types.proto
Run Code Online (Sandbox Code Playgroud)
我有一种感觉,我错过了一些简单的东西.
我正试图用一个Expression内部LINQ Select.这是我的代码示例
Expression<Func<user, string>> expr = d => d.user.username;
Message.Select(b => new { name = b.user.Select(expr) });
Run Code Online (Sandbox Code Playgroud)
消息属于类型IEnumerable,在运行时我收到以下错误:
The exception message is ''System.Collections.Generic.List<W.Models.user>' does not contain a definition for 'Select'
我该如何解决?
c# ×6
.net ×2
linq ×2
collections ×1
datatable ×1
enums ×1
expression ×1
generics ×1
ienumerable ×1
java ×1
linux ×1
mono ×1
nullable ×1
objective-c ×1
reflection ×1
regex ×1
select ×1
singleton ×1