我正在构建使用"枚举"作为变量名称的相当旧的Java代码,并且我得到"枚举无法解析为变量"错误.如何删除错误?
<OLD JAVA CODE>
Enumeration enum = props.propertyNames();
while (enum.hasMoreElements()) {
Run Code Online (Sandbox Code Playgroud)
在此站点之后,我尝试将编译器合规性级别设置为1.3,但它不起作用.


我正在尝试在 Mac OS X Lion 上构建 64 位 Tcl/Tk。
./configure --enable-framework --enable-64-bit --prefix=/usr/localmakesudo make install一切工作正常,但使用时make install,我遇到版本冲突错误。
Installing private header files to
/Library/Frameworks/Tcl.framework/Versions/8.6/PrivateHeaders/
ERROR: version conflict for package "Tcl": have 8.5.9, need 8.6
If running this script from 'make html', set the NATIVE_TCLSH environment
variable to point to an installed tclsh8.6 (or the equivalent tclsh86.exe
on Windows).
make: *** [html-tcl] Error 1
Run Code Online (Sandbox Code Playgroud)
什么地方出了错?如何修复这个错误?
我下载了gtest 1.6,并用clang ++编译.
我得到了libgtest.a,然后将其复制到了/usr/local/lib/libgtest_clang.a.
当我使用简单的C++代码进行测试时,一切正常,但是,当我尝试在测试代码中使用向量时,我在构建过程中收到了这些错误消息.编译工作正常.
Undefined symbols for architecture x86_64:
"std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::find(wchar_t const*, unsigned long, unsigned long) const", referenced from:
testing::AssertionResult testing::(anonymous namespace)::IsSubstringImpl<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >(bool, char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) in libgtest_clang.a(gtest-all.o)
...
Run Code Online (Sandbox Code Playgroud)
这是我用于构建的命令行.
clang++ -DGTEST_USE_OWN_TR1_TUPLE=1 -std=c++11 -stdlib=libc++ main.cpp test_a.cc \
-L/usr/local/lib -I. -lgtest_clang -o t
Run Code Online (Sandbox Code Playgroud)
这是测试中的测试代码和代码.
#include <limits.h>
#include <time.h>
#include <gtest/gtest.h>
#include <list>
#include …Run Code Online (Sandbox Code Playgroud) 我有来自DZone(http://www.dzone.com/links/r/java_custom_serialization_example.html)的代码,它将Java对象从/向文件序列化/反序列化.
final class Hello implements Serializable
{
int x = 10;
int y = 20;
public int getX()
{
return x;
}
public int getY()
{
return y;
}
}
public class SerializedComTest {
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Test
public void testFile() throws IOException, ClassNotFoundException {
Hello h = new Hello();
FileOutputStream bs = new FileOutputStream("hello.txt"); // ("testfile");
ObjectOutputStream out = new ObjectOutputStream(bs);
out.writeObject(h);
out.flush();
out.close();
Hello h2;
FileInputStream fis = new FileInputStream("hello.txt"); …Run Code Online (Sandbox Code Playgroud) 我正在尝试将OUnit与OCaml一起使用.
单位代码源(unit.ml)如下:
open OUnit
let empty_list = []
let list_a = [1;2;3]
let test_list_length _ =
assert_equal 1 (List.length empty_list);
assert_equal 3 (List.length list_a)
(* etc, etc *)
let test_list_append _ =
let list_b = List.append empty_list [1;2;3] in
assert_equal list_b list_a
let suite = "OUnit Example" >::: ["test_list_length" >:: test_list_length;
"test_list_append" >:: test_list_append]
let _ =
run_test_tt_main suite
Run Code Online (Sandbox Code Playgroud)
有了ocamlc unit.ml,我收到了一条错误消息Error: Unbound module OUnit.为什么是这样?如何在OCaml中使用OUnit.我安装了OUnit opam.
我有这个python线程代码。
import threading
def sum(value):
sum = 0
for i in range(value+1):
sum += i
print "I'm done with %d - %d\n" % (value, sum)
return sum
r = range(500001, 500000*2, 100)
ts = []
for u in r:
t = threading.Thread(target=sum, args = (u,))
ts.append(t)
t.start()
for t in ts:
t.join()
Run Code Online (Sandbox Code Playgroud)
执行这个,我有数百个线程正在工作。

但是,当我在 t.start() 之后立即移动 t.join() 时,我只有两个线程在工作。
for u in r:
t = threading.Thread(target=sum, args = (u,))
ts.append(t)
t.start()
t.join()
Run Code Online (Sandbox Code Playgroud)

我用不调用 t.join()的代码进行了测试,但它似乎工作正常?
那么何时、如何以及如何使用 thread.join()?
我试图使用Python装饰器来捕获异常并记录异常.
import os.path
import shutil
class log(object):
def __init__(self, f):
print "Inside __init__()"
self.f = f
def __call__(self, *args):
print "Inside __call__()"
try:
self.f(*args)
except Exception:
print "Sorry"
@log
def testit(a, b, c):
print a,b,c
raise RuntimeError()
if __name__ == "__main__":
testit(1,2,3)
Run Code Online (Sandbox Code Playgroud)
它工作正常
Desktop> python deco.py
Inside __init__()
Inside __call__()
1 2 3
Sorry
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试使用doctest进行测试时
@log
def testit(a, b, c):
"""
>>> testit(1,2,3)
"""
print a,b,c
raise RuntimeError()
if __name__ == "__main__":
import doctest
doctest.testmod()
Run Code Online (Sandbox Code Playgroud)
似乎没有任何事情发生.
Desktop> python deco2.py
Inside …Run Code Online (Sandbox Code Playgroud) 使用ByteBuffer,我可以将字符串转换为字节数组:
val x = ByteBuffer.allocate(10).put("Hello".getBytes()).array()
> Array[Byte] = Array(104, 101, 108, 108, 111, 0, 0, 0, 0, 0)
Run Code Online (Sandbox Code Playgroud)
将字节数组转换为字符串时,我可以使用new String(x).但是,字符串变为hello?????,我需要在将字节数组转换为字符串之前对其进行修剪.我怎样才能做到这一点?
我使用这段代码来减少零,但我想知道是否有更简单的方法.
def byteArrayToString(x: Array[Byte]) = {
val loc = x.indexOf(0)
if (-1 == loc)
new String(x)
else if (0 == loc)
""
else
new String(x.slice(0,loc))
}
Run Code Online (Sandbox Code Playgroud) 我可以将Int数据转换为Byte.
scala> 10.asInstanceOf[Byte]
res8: Byte = 10
Run Code Online (Sandbox Code Playgroud)
但是,如果使用任何类型的相同值,则转换会引发错误.
scala> val x : Any = 10
x: Any = 10
scala> x.asInstanceOf[Byte]
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Byte
at scala.runtime.BoxesRunTime.unboxToByte(BoxesRunTime.java:98)
at .<init>(<console>:10)
Run Code Online (Sandbox Code Playgroud)
我可以投两次.
scala> val y = x.asInstanceOf[Int]
y: Int = 10
scala> y.asInstanceOf[Byte]
res11: Byte = 10
Run Code Online (Sandbox Code Playgroud)
还有比这更好的方法吗?
我在Haskell中有这个代码.
import Data.List
main = do
putStrLn $ "\nVerify if Exists in a String"
let wordlist = ["monad", "monoid", "Galois", "ghc", "SPJ"]
let tweet = "This is an example tweet talking about SPJ interviewing with Galois"
print $ map (flip isInfixOf tweet) wordlist
Run Code Online (Sandbox Code Playgroud)
没有let,我有这个错误信息:10_things.hs:16:14: parse error on input ‘=’.
这是另一个工作正常的代码.
import Data.List
wordlist = ["monad", "monoid", "Galois", "ghc", "SPJ"]
tweet = "This is an example tweet talking about SPJ interviewing with Galois"
main = do
putStrLn …Run Code Online (Sandbox Code Playgroud)