shadowing

Java Inner class shadowing external class

℡╲_俬逩灬. 提交于 2019-12-23 10:57:44
问题 I took the following code from the K&B book "SCJP Sun Certified Programmer for Java 6 Study Guide": class A { // 1 void m() { System.out.println("outer"); } } public class TestInners { public static void main(String[] args) { new TestInners().go(); } void go() { new A().m(); class A { // 2 void m() { System.out.println("inner"); } } } class A { // 3 void m() { System.out.println("middle"); } } } As stated in the book, this code prints "middle". I infer that the class declaration marked as "3"

How do I find where a variable is defined at runtime?

好久不见. 提交于 2019-12-23 07:12:22
问题 I've been using jQuery and YUI side-by-side with no issues until recently. Occasionally, inside of a callback for, say, a YUI button, $ will be shadowed by some other function (click for big version): and for the life of me, I cannot figure out why this is happening . Yes, I know I could be safe and use jQuery or window.$ everywhere instead of just $ , but that's just a workaround and not an actual fix. At runtime, how can I find where this $ impostor is coming from? - e.g. find where it's

Is there a way to have warnings for shadowing values in F# in Visual Studio?

喜欢而已 提交于 2019-12-19 17:32:35
问题 To me shadowing of existing values like described in: Shadowing and Nested function immutable in F# f# duplicate definition FSharp for fun and profit comment seems to be going against the notion of immutability and type safety that makes F# so strong. Shadowing in F# works different than in C#. It just took me quite some time to find out that a bug in my code was due to unintentional shadowing of a name within the same scope. Is there a way to have compiler warnings for shadowing values in VS

Assignment operator in f#

余生长醉 提交于 2019-12-17 20:39:06
问题 i have seen in ruby as well powershell programming we can assign variables like a,b=b,a . it actually swaps the variable . Is this possible in f# if so please guide me with some reference 回答1: Generally, F# doesn't allow variable re-assignment. Rather it favors immutable named values via let bindings. So, the following is not possible: let a = 3 a = 4 Unless you explicitly mark a as mutable : let mutable a = 3 a <- 4 However, F# does allow in most situations variable "shadowing". The only

Lambda capture and parameter with same name - who shadows the other? (clang vs gcc)

爷,独闯天下 提交于 2019-12-17 10:35:19
问题 auto foo = "You're using g++!"; auto compiler_detector = [foo](auto foo) { std::puts(foo); }; compiler_detector("You're using clang++!"); clang++ 3.6.0 and newer print out "You're using clang++!" and warn about the capture foo being unused. g++ 4.9.0 and newer print out "You're using g++!" and warn about the parameter foo being unused. What compiler is more accurately following the C++ Standard here? wandbox example 回答1: Update: as promised by the Core chair in the bottom quote, the code is

Shadowing and Nested function

痞子三分冷 提交于 2019-12-17 05:13:33
问题 I want to understand how the mechanism of Shadowing and Nested function work. For example: let func y = let dup y = y + y let z = dup y let dup y = let dup z = let y = y * z y let z = y y dup z + z;; val func : int -> int > func 3;; val it : int = 12 Can someone explain what happen here? 回答1: Your code is equivalent to the following, where I've simply numbered instances of your names to help you visualize how shadowing is occurring. let func y0 = let dup0 y1 = y1 + y1 let z0 = dup0 y0 let

ASP.NET: Shadowing Issues

情到浓时终转凉″ 提交于 2019-12-13 03:41:05
问题 I have two classes in two separate libraries (one VB, one C#): Public Class Item ... Public Overridable ReadOnly Property TotalPrice() As String Get Return FormatCurrency(Price + SelectedOptionsTotal()) End Get End Property End Class and public class DerivedItem : Item { ... public new Decimal TotalPrice { get { return Price + OptionsPrice; } } } As you can see, the DerivedItem.TotalPrice shadows the Item.TotalPrice property. However, when trying to retrieve the DerivedItem.TotalPrice value,

Scala: How to access a shadowed function variable from an object

拜拜、爱过 提交于 2019-12-11 12:44:36
问题 I would like to make the following work: def foo(x:Int = 1) = { object obj { val x = foo.this.x } } But I don't know how to reference x from within the object. Can this be done without renaming x in one of the two spots? Renaming the variables may not be easy when, for example, foo is a widely used API function with x as a named variable, while obj extends a 3rd party trait that has x as an abstract member. 回答1: Why not just introduce a new variable that has the same value as foo 's argument

Prevent Shadowed Property From Getting Serialized

孤人 提交于 2019-12-11 04:25:53
问题 This is kind of piggybacking off of this question: ASP.NET: Shadowing Issues I've discovered that the issue isn't actually that the property isn't getting serialized, it is, but that BOTH the shadowed and shadowing properties are getting serialized, and since the shadowed property is being serialized second, its value is the one that is available via JSON to my Javascript. My serialization code looks like this. How can I ensure that my shadowed property does not get serialized, while still

Variable shadowing and testing for existence before assignment in javascript

Deadly 提交于 2019-12-10 17:14:36
问题 In the following code snippet I declare a global variable and then check for its presence inside a function. <script> x = 5; $(function() { var x = x || 3; console.log(x); // prints 3 }); </script> This behaves differently: <script> x = 5; $(function() { var y = x || 3; console.log(y); // prints 5 }); </script> I expect that in the first example, the variable declaration in the inner scope will detect that x already exists in the global scope, and take its value. Why does the first example 3?