language-features

Any differences between asInstanceOf[X] and toX for value types?

怎甘沉沦 提交于 2019-12-13 11:54:05
问题 I used IntelliJ's ability to convert Java code to Scala code which generally works quite well. It seems that IntelliJ replaced all casts with calls to asInstanceOf . Is there any valid usage of asInstanceOf[Int] , asInstanceOf[Long] etc. for value types which can't be replaced by toInt , toLong , ...? 回答1: I do not know of any such cases. You can check yourself that the emitted bytecode is the same by compiling a class like class Conv { def b(i: Int) = i.toByte def B(i: Int) = i.asInstanceOf

Abstracting over Collection Types

纵饮孤独 提交于 2019-12-13 03:49:15
问题 Is there a possibility of writing functions which are generic in respect to collection types they support other than using the seq module? The goal is, not having to resort to copy and paste when adding new collection functions. 回答1: The seq<'T> type is the primary way of writing computations that work for any collections in F#. There are a few ways you can work with the type: You can use functions from the Seq module (such as Seq.filter , Seq.windowed etc.) You can use sequence

Accessing internal property out of the assembly scope

感情迁移 提交于 2019-12-12 22:22:33
问题 I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter logic } set { ..setter logic } } However I want to be able to access to this property outside of the assembly so I created method that simply returns this property: public StateEnum GetCurrentState() { return EnrolmentState; } But when I call this method from class outside of this assembly I get an exception (System.TypeLoadException: Method 'get_EnrolmentState' on type 'EnrolmentAopProxy' from

GOTO command in PHP?

这一生的挚爱 提交于 2019-12-12 10:55:46
问题 I've heard rumors that PHP is planning on introducing a "goto" command. What is it supposed to be doing? I've tried searching a bit, but haven't found anything awfully descriptive. I understand that it won't be a " GOTO 10 "-like command... 回答1: They are not adding a real GOTO, but extending the BREAK keyword to use static labels. Basically, it will be enhancing the ability to break out of switch nested if statements. Here's the concept example I found: <?php for ($i = 0; $i < 9; $i++) { if

C# internal VS VBNET Friend

旧时模样 提交于 2019-12-12 10:29:46
问题 To this SO question: What is the C# equivalent of friend?, I would personally have answered "internal", just like Ja did among the answers! However, Jon Skeet says that there is no direct equivalence of VB Friend in C#. If Jon Skeet says so, I won't be the one telling otherwise! ;P I'm wondering how can the keyword internal (C#) not be the equivalent of Friend (VBNET) when their respective definitions are: Friend VBNET The Friend (Visual Basic) keyword in the declaration statement specifies

Why can't I do ??= in C#?

给你一囗甜甜゛ 提交于 2019-12-12 09:31:59
问题 I often find myself doing: foo = foo ?? x; Why can't I do: foo ??= x; Edit : I know it's not part of the language... My question is "why not"? I find the necessity to repeat "foo" to be unpleasing and potentially error-prone. It looks just as ugly as: foo = foo + x; 回答1: In general, the C# language design team is conservative about adding new syntax. They say that the value of an addition to the language must be weighed against the cost of increased complexity in the language. Peter Hallam

What's the next big thing after LINQ? [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-12 08:01:15
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago . I started using LINQ (Language Integrated Query) when it was still in beta, more specifically Microsoft .NET LINQ Preview (May 2006).

Assigning const value to const error in php

北慕城南 提交于 2019-12-11 06:05:54
问题 <?php class Lala { const a = "a"; const b = a . "b"; } ?> Parse error: syntax error, unexpected '(', expecting ',' or ';' on line 4 What's the problem with it? 回答1: From the documentation: The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call. See http://www.php.net/manual/en/language.oop5.constants.php 回答2: mb <?php class Lala { const A = "a"; const B = self::A . "b"; } ?> 来源: https://stackoverflow.com

for object in collection where object inherits

邮差的信 提交于 2019-12-11 02:01:50
问题 In objective-c, is for (Foo *foo in fooList) ... more like which of the following @interface Bar : Foo ... for (Foo *f in fooList) { // A: if ([f isMemberOfClass:[Foo class]]) ... // dont include Bar's // B: if ([f isKindOfClass:[Foo class]]) ... // both Foos and Bars } 回答1: It's not like either. The type of foo in the for() part is only a hint to the compiler so it can give out the relevant error messages. At run time, all the objects are just objects and as long as they all implement the

Java Upside Down Text - Bug or Feature?

扶醉桌前 提交于 2019-12-10 17:13:08
问题 While playing around with the Java font class and Swing, I set the font size to a negative value. I discovered that this makes the text be drawn upside down. Is this a bug or a feature? Can anyone explain why this behavior happens? Try it out: import java.awt.Font; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class UpsideDown extends JFrame{ public UpsideDown(){ setSize(500,500); setContentPane(new Panel()); setVisible(true); } public class Panel