我想声明一个枚举方向,它有一个方法返回相反的方向(下面的语法不正确,即枚举不能实例化,但它说明了我的观点).这在Java中可行吗?
这是代码:
public enum Direction {
NORTH(1),
SOUTH(-1),
EAST(-2),
WEST(2);
Direction(int code){
this.code=code;
}
protected int code;
public int getCode() {
return this.code;
}
static Direction getOppositeDirection(Direction d){
return new Direction(d.getCode() * -1);
}
}
Run Code Online (Sandbox Code Playgroud) 在iOS中,在UIViewController的视图中有一个嵌套的视图控制器视图通常是不好的编程习惯吗?比方说,我希望有某种响应用户触摸的互动元素,但只占屏幕的25%.
我想我会把这个嵌套的视图控制器添加到我的UIViewController中,例如:
[self.view addSubview: nestedViewController.view];
Run Code Online (Sandbox Code Playgroud) 我想这更像是一个关于语言理论的问题而不是其他任何问题.为什么第一个声明是主要法律,第二个声明不是?他们不认为是同一件事吗?
public class Main {
public static void main(String[] args) {
foo();
0;
}
public static int foo(){
return 0;
}
}
Run Code Online (Sandbox Code Playgroud) 我试图将我的.spl
文件转换为C文件(因为没有编译器).我有一个示例"Hello World".spl文件,我已经下载了莎士比亚编程语言 .tar
并将其解压缩,但我不知道下一步该怎么做.我似乎无法在任何文档中找到说明.有人可以帮忙吗?
编辑:
当我输入时make -f "Makefile"
,我得到以下输出:
bison --verbose -d grammar.y
gcc -O2 -Wall -c grammar.tab.c
gcc -O2 -Wall -c makescanner.c
gcc makescanner.o -O2 -Wall -o makescanner
./makescanner include > scanner.l
flex -Cem -t scanner.l > scanner.c
scanner.l:600: warning, rule cannot be matched
gcc -O2 -Wall -c scanner.c
<stdout>:5823: warning: ‘yyunput’ defined but not used
gcc -O2 -Wall -c strutils.c
gcc grammar.tab.o scanner.o strutils.o -O2 -Wall -lfl -o spl2c
ld: library not found for …
Run Code Online (Sandbox Code Playgroud) compiler-construction dependencies compiler-errors bison flex-lexer
我编写了一个名为Main.java的.java文件,并使用Windows命令提示符中的javac编译它.编译器正在创建多个.class文件(称为Main.class,Main $ 1.class,&Main $ 2.class - 可能是因为我在Main.java文件中有匿名内部类).我正在尝试创建一个可运行的.jar文件,因此我可以双击快捷方式来运行此应用程序(它是一个Java Swing应用程序),但是当我导航到三个类文件的目录并输入时,我不成功:
jar cfv file.jar Main.class Main$1.class Main$2.class
Run Code Online (Sandbox Code Playgroud)
命令提示符然后输出此文本:
added manifest
adding: Main.class(in 4871) (out = 2848)(deflated 41%)
adding: Main$1.class(in 1409) (out = 833)(deflated 40%)
adding: Main$2.class(in 1239) (out = 767)(deflated 38%)
Run Code Online (Sandbox Code Playgroud)
尽管如此,当我在Windows资源管理器中双击file.jar文件时,简单地说,没有任何反应.没有摆动应用程序打开
希望有人可以帮助我解决这个问题.谢谢
最佳... SL
我正在尝试建立一个琐碎的EMR作业,以对存储在中的大量文本文件进行字数统计s3://__mybucket__/input/
。我无法正确添加两个必需的流传输步骤中的第一个(第一步是将输入映射到wordSplitter.py
,使用减少IdentityReducer
到;到第二步是使用映射此辅助存储的内容/bin/wc/
,然后再减少IdentityReducer
一次)。
这是第一步的(失败)描述:
Status:FAILED
Reason:S3 Service Error.
Log File:s3://aws-logs-209733341386-us-east-1/elasticmapreduce/j-2XC5AT2ZP48FJ/steps/s-1SML7U7CXRDT5/stderr.gz
Details:Exception in thread "main" com.amazon.ws.emr.hadoop.fs.shaded.com.amazonaws.services.s3.model.AmazonS3Exception: Bad Request (Service: Amazon S3; Status Code: 400; Error Code: 400 Bad Request; Request ID: 7799087FCAE73457), S3 Extended Request ID: nQYTtW93TXvi1G8U4LLj73V1xyruzre+uSt4KN1zwuIQpwDwa+J8IujOeQMpV5vRHmbuKZLasgs=
JAR location: command-runner.jar
Main class: None
Arguments: hadoop-streaming -files s3://elasticmapreduce/samples/wordcount/wordSplitter.py -mapper wordSplitter.py -reducer org.apache.hadoop.mapred.lib.IdentityReducer -input s3://__mybucket__/input/ -output s3://__mybucket__/output/
Action on failure: Continue
Run Code Online (Sandbox Code Playgroud)
这是发送到hadoop集群的命令:
JAR location : command-runner.jar
Main class : None
Arguments : hadoop-streaming -mapper s3a://elasticmapreduce/samples/wordcount/wordSplitter.py …
Run Code Online (Sandbox Code Playgroud) 我有一个数组数组.包含的数组的第一个元素都是NSDate对象.我想按顺序从最新到最少排序包含数组的数组.由于某种原因,下面的排序算法导致无限循环.谁能帮我吗?谢谢.
最佳... SL
//array is the array containing all of the other arrays(that have NSDates as their first elements)
//temp is the new array being added to the end of the array, to later be sorted into the correct position.
[array addObject:temp];
NSMutableArray *tempArray;
for (int i=0; i<[array count]; i++)
{
NSDate *session1, *session2;
session1 = [[array objectAtIndex:i] objectAtIndex:0];
session2 = [[array objectAtIndex:[array count]-1] objectAtIndex:0];
if([session1 compare:session2] == NSOrderedDescending)
{
tempArray = [array objectAtIndex:i];
[array insertObject:[array objectAtIndex:[array count]-1] atIndex:i];
[array …
Run Code Online (Sandbox Code Playgroud) java ×3
ios ×2
amazon-s3 ×1
bison ×1
command-line ×1
dependencies ×1
enumeration ×1
enums ×1
flex-lexer ×1
hadoop ×1
jar ×1
javac ×1
nsdate ×1
semantics ×1
sorting ×1