考虑具有相同实体的两个迭代器方法:
public static IEnumerable<int> It1() {
...
}
public static IEnumerator<int> It2() {
...
}
Run Code Online (Sandbox Code Playgroud)
呼叫It2与呼叫有It1.GetEnumerator()什么不同吗?
是否有充分的理由将迭代器定义为IEnumerator<T>结束IEnumerable<T>?我能想到的唯一一个就是你实施的时候IEnumerable<T>.GetEnumerator().
编辑:通过迭代器方法我的意思是使用yield return和yield break构造的方法.
T4是C#/ VB.NET的"官方"代码生成引擎.但F#不支持它(这是从四月开始,但我找不到任何新的提及).那么生成F#代码的好方法是什么?
编辑:
我想在F#中实现2-3个手指树.我已经在C#中实现了它们,所以这应该是一个很好的比较.树的"数字"和节点可以表示为数组,因此
type 't FingerTree = Empty | Single of 't | Deep of 't array * (('t FingerTree) array) lazy * 't array
Run Code Online (Sandbox Code Playgroud)
但是,这些数组的最大大小非常小,所以很高兴
type 't Digit = Digit1 of 't | Digit2 of 't*'t | Digit3 of 't*'t*'t | Digit4 of 't*'t*'t*'t
type 't Node = Node2 of 't FingerTree * 't FingerTree | Node3 of 't FingerTree * 't FingerTree * 't FingerTree
type 't FingerTree = Empty | Single of …Run Code Online (Sandbox Code Playgroud) 我似乎记得Scala处理_=特别结束的方法,所以这样的事情:
object X { var x: Int = 0; def y_=(n : Int) { x = n }}
X.y = 1
Run Code Online (Sandbox Code Playgroud)
应该打电话X.y_=(1).但是,在2.8.0 RC1中,我收到一条错误消息:
<console>:6: error: value y is not a member of object X
X.y = 1
^
Run Code Online (Sandbox Code Playgroud)
有趣的是,只是尝试调用没有括号的方法也失败了:
scala> X.y_= 1
<console>:1: error: ';' expected but integer literal found.
X.y_= 1
^
Run Code Online (Sandbox Code Playgroud)
我是否错误地记住了确实存在的东西,或者我只是用整块布来发明它?
根据这篇文章,在.Net中,
终结者实际上甚至比这更糟糕.除了它们运行较晚(这对于许多种资源确实是一个严重的问题),它们也不那么强大,因为它们只能执行析构函数中允许的操作的子集(例如,终结器不能可靠地使用其他对象,而析构函数可以),甚至在写入子集时终结器也很难正确编写.并且收集可终结的对象是昂贵的:每个可终结的对象,以及可从其获得的对象的潜在巨大图形,被提升到下一代GC生成,这使得通过一些大的倍数收集它更加昂贵.
这是否也适用于一般的JVM,特别是HotSpot?
我确定我的Git repo的两个分支应该只在一个文件中有所不同.确保这一点的最简单方法是完成所有工作branch1,并branch2在我切换到它时将其合并(包装到shell脚本中,因此每个交换机只需要一个命令).但是,有没有办法以更少的工作来做到这一点?
有了这个persistence.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="ODP_Server_Test"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<!-- <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/ODPServerDataSource)</non-jta-data-source> -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:unit-testing;create=true" />
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.target-database" value="DERBY" />
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
一个简单的测试:
public class RepositoryTest {
private static Logger logger = LoggerFactory
.getLogger(RepositoryTest.class);
private static EntityManagerFactory emf;
private EntityManager em;
private RepositoryImpl repo = new RepositoryImpl();
@BeforeClass
public static void setUp() { …Run Code Online (Sandbox Code Playgroud) 我的Eclipse安装完全被borked并且无法启动,所以我可能不得不重新安装它(但这在升级到新的Eclipse版本时也是相关的).我不想找到我安装的所有插件.那么Eclipse在哪里存储可用更新站点的列表?如果它不是纯文本,是否可以毫无问题地复制到另一个安装中?
Java NumberFormat是1)非线程安全的(可以使用a ThreadLocal); 2)当我知道字符串是否应该包含int,long或double,并且想要一个像这样的API时,对于最简单的用例,使用不正确是不方便的:
int parseInt(String str, Locale locale) throws ParseException;
int parseInt(String str, int defaultValue, Locale locale);
long parseLong(String str, Locale locale) throws ParseException;
long parseLong(String str, long defaultValue, Locale locale);
double parseDouble(String str, Locale locale) throws ParseException;
double parseDouble(String str, double defaultValue, Locale locale);
Run Code Online (Sandbox Code Playgroud)
字符串未完全解析时抛出异常的位置.显然,这样的包装器很容易编写,但我在Guava或Apache Commons Lang中找不到.我错过了吗?或者是否有其他或多或少的标准解决方案?
class C {
object O
}
val x: C#O.type = (new C).O // error: ';' expected but '.' found
val y: C#(O.type) = (new C).O // error: identifier expected but '(' found
Run Code Online (Sandbox Code Playgroud)
这种类型有合法的语法吗?
编辑:
val x: c.O.type forSome { val c: C } = (new C).O
Run Code Online (Sandbox Code Playgroud)
给
ScalaFiddle.scala:4: error: type mismatch;
found : ScalaFiddle.this.C#O.type
required: c.type#O.type forSome { type c.type <: ScalaFiddle.this.C with scala.this.Singleton{} }
val x: c.O.type forSome { val c: C } = (new C).O
^
Run Code Online (Sandbox Code Playgroud)
所以Scala编译器理解这种类型并将其显示为C#O.type …