我是通配符的新手,并且在迭代Collection类型时遇到问题.我不得不将此函数转换为适用于任何Collection类型,而不仅仅是List,这就是我所做的:
void sell(List<T> items) {
for (T e : items) {
stock.add(e);
}
}
Run Code Online (Sandbox Code Playgroud)
变成:
void sell(Collection<? super T> items) {
Iterator ir = items.iterator();
while (ir.hasNext()){
stock.add((T)ir.next());
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我编译代码时,我收到错误:
Note: Shop.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)
我没有正确使用迭代吗?任何帮助表示赞赏!
我的老师给了我们一些示例代码,以帮助显示Java中的反射是如何工作的,但是我收到了一些错误:
Note: DynamicMethodInvocation.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)
这是代码:
import java.lang.reflect.*;
import java.lang.Class;
import static java.lang.System.out;
import static java.lang.System.err;
public class DynamicMethodInvocation {
public void work(int i, String s) {
out.printf("Called: i=%d, s=%s%n\n", i, s);
}
public static void main(String[] args) {
DynamicMethodInvocation x = new DynamicMethodInvocation();
Class clX = x.getClass();
out.println("class of x: " + clX + '\n');
// To find a method, need array of matching Class types.
Class[] argTypes = { …Run Code Online (Sandbox Code Playgroud) 我想把函数参数放到一个数组中,我无法想象我的生活.labelPoi是一个包含imageLocationX,imageLocationY和name的对象类.我试图将一个ViewController中找到的值分配给另一个ViewController中的值,但它对我不起作用.
这是我的第一个ViewController
PointOfInterest.imageLocationX = (((([self getDegreesFromRadians:angle_horizontal] / [self getDegreesFromRadians:FOV_Horizontal]))) *1024);
PointOfInterest.imageLocationY = ((1-(([self getDegreesFromRadians:angle_to_bottom_of_view] / [self getDegreesFromRadians:FOV_Vertical])))*576);
PictureViewController *newlabel = [[PictureViewController alloc] display:PointOfInterest.imageLocationX andY:PointOfInterest.imageLocationY withName:PointOfInterest.name];
Run Code Online (Sandbox Code Playgroud)
这是我的第二个ViewController(PictureViewController)
- (id)display:(double)imageXX andY:(double)imageYY withName:(NSString *)namee{
NSLog(@"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
NSLog(@"imageX: %f",imageXX);
NSLog(@"imageY: %f", imageYY);
NSLog(@"name: %@", namee);
labelPoi.imageLocationX = imageXX;
labelPoi.imageLocationY = imageYY;
labelPoi.name = name;
[transfer addObject:labelPoi];
NSLog(@"label.x: %f should be: %f", labelPoi.imageLocationX, imageXX);
NSLog(@"label.y: %f should be: %f", labelPoi.imageLocationY, imageYY);
NSLog(@"label.name: %@ should be: %@",labelPoi.name,namee);
return self;
Run Code Online (Sandbox Code Playgroud)
}
这是输出:
2013-07-18 14:21:14.731 AR_UAV_App[10641:11303] %%%%%%%%%%%%%%%%%%%%%%%%
2013-07-18 14:21:14.731 …Run Code Online (Sandbox Code Playgroud)