I've been trying to use Dart's noSuchMethod(), but this code
noSuchMethod(InvocationMirror invocation) {
// ...
}
results in the following error: cannot resolve class name 'InvocationMirror' from 'MyClass'
It looks like there's no such class as InvocationMirror. Could it be an older version of dart which doesn't have it? The one I have is the stable one from SDK for Mac downloaded just today.
You're observing an inconsistency between specification and implementation (which shouldn't come as a surprise, there are a lot of them). You can use noSuchMethod, at least on Dart VM (don't know about dart2js), but it looks like this: noSuchMethod(String name, List arguments). In the future, when reflection finally comes to Dart, it will change.
You can currently not use the InvocationMirror class as mirror based reflection is not yet implemented in Dart (as mentioned in this article).
Related
The following gives a runtime error on the last line but why do I not receive a compile time error?
Why is this? fnSub (last line) accepts a type of Sub but here I'm passing it a type of Parent and it compiles. Ok, I do get a runtime error but I'd have thought this should have given me a compile time error. Is this a bug in Dart or am I misunderstanding the limitations of the type system or have I just gone crazy?
class Parent {}
class Sub implements Parent {
String get blah => "blah";
}
String fnSub(Sub sub) => sub.blah;
String aProblem(Parent parent) => fnSub(parent);
https://dartpad.dev/acd2767cd42371deae0644fa66e8c602
The problem is that implicit-casts are enabled by default in Dart which is a feature trying to make it easier to work around types in Dart by automatically adding type casts in your code base.
This feature will no longer be available when NNBD (Non-nullable by default) are coming where implicit-dynamic also will be gone. Both features can already be disabled today by following this guide: https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks
Personally, I think most projects should disable this two features already since I have seen a lot of people on Stackoverflow being confused about what Dart are doing with the types. So I cannot wait for NNBD so we can get are lot more clear type experience in Dart. And hopefully, the errors from the analyzer will be clear enough for most people so they don't need to get help.
If you disable implicit-casts you code will fail at the following line:
String aProblem(Parent parent) => fnSub(parent);
And with this error:
error - The argument type 'Parent' can't be assigned to the parameter type 'Sub'. - bin\stackoverflow.dart:9:41 - argument_type_not_assignable
If you want to test with Dartpad you can try with the following edition based on a beta version of the next Dart version which has enabled null-safety (and therefore have no implicit-casts): https://nullsafety.dartpad.dev/
My question is really a repeat of an old question posted here:
Ninject 2.2 multiple bindings
It seems someone was going to deal with this back in 2011. Does anyone know if there is some way to turn off such warnings in Ninject? Or some other workaround?
EDIT
In response to #BatteryBackupUnit, here is my exact problem:
I have multiple libraries... and in my core library, I do something like this:
Find all assemblies referenced by the host application (including the host)
Find all types inheriting from IDependency from all those assemblies.
Automatically register all of those as transient
Then from another library (which may or may not be referenced by the host app), I have this:
Kernel.Bind<IDbContextFactory>().To<DbContextFactory>().InSingletonScope();
Here IDbContextFactory is also an IDependency, so it got loaded already by the core library and now I register it here but with a different scope (singleton).
From experience (and having tested it earlier) I know this is no problem in Autofac, but Ninject gives me that error message about having already registered it.
Ideally it would be better to just override any previous registrations... "cascade style" (for lack of a better phrase)..
Ninject does now support overriding open generic bindings with more specific ones.
For Example:
public interface IFoo<T> { }
public class Foo<T> : IFoo<T> { }
public class StringFoo : IFoo<string> {}
used like:
var kernel = new StandardKernel();
kernel.Bind(typeof(IFoo<>)).To(typeof(Foo<>));
kernel.Bind<IFoo<string>>().To<StringFoo>();
var intFooInstance = kernel.Get<IFoo<int>>();
var stringFooinstance = kernel.Get<IFoo<string>>();
Works.
However, if you're not talking about open generic bindings, ninject 3 still handles multi bindings the same as ninject 2.2.
In most scenarios you can work around this by using contextual bindings. Okay i would not exactly call it a workaround, i would call it good design.
In general this is described here: https://github.com/ninject/ninject/wiki/Contextual-Binding
A simple way would be to specify the binding using a name. This requires one binding for the specified one and allows only one, too.
See: https://github.com/ninject/ninject/wiki/Contextual-Binding#simple-constrained-resolution-named-bindings
It is also possible to define a "default" binding like .Bind<IFoo>().To<Foo>(); and special case bindings with the .When(...) syntax, like:
.Bind<IFoo>().To<SpecialFoo>().When(ctx => ...)
See https://github.com/ninject/ninject/wiki/Contextual-Binding#specifying-constraints-on-the-type-binding-using-arbitrary-elements-of-the-resolution-request-context
If you show us your concrete problem we might be able to provide a more concrete solution.
Using the ideas outlined in ding the article Using Dart with JSON Web Services at https://www.dartlang.org/articles/json-web-service/, I have been trying to implement the section on using JsonObject and interfaces to produce a strong typing of JSON data.
The article indicates that one should write something like.
abstract class Language {
String language;
List targets;
Map website;
}
class LanguageImpl extends JsonObject implements Language {
LanguageImpl();
factory LanguageImpl.fromJsonString(string) {
return new JsonObject.fromJsonString(string, new LanguageImpl());
}
}
However the compiler 'fail' at the definition of the class LanguageImpl with the message
Missing inherited members: 'Language.website', 'Language.targets' and
'Language.language'
Even more confusing the code will run without a problem....
In Darteditor you get Quick fix support for this.
Set the caret at LanguageImpl and press ctrl+1 or use the context menu > Quick fix.
You get the missing concrete implementations you inherit from the abstract base class generated automatically.
Dart is a dynamic language and therefor very flexible.
The tools support you and try to give meaningful warnings and hints about what could go wrong
but don't prevent you running a program even when it is not yet finished.
You can use the #proxy annotation on the class to silent the warnings.
This also needs the class to have a noSuchMethod() implementation.
I am trying to create a class implementing Blackberry's Comparator so I can easily sort 2D arrays.
import net.rim.device.api.util.Comparator;
class ArrayComparator implements Comparator<Object[]> {
...
}
This gives me the error:
The Type Comparator is not generic; it can not be parameterized with
arguments <Object[]>
This error goes away if I include the normal JRE library and import java.util.Comparator, but this won't compile because it is a mobile device, the library is not preverified, etc, etc, etc.
How can I resolve this issue?
net.rim.device.api.util.Comparator doesn't have Generic capabilities. You need to implement Comparator without any type information and compare all the items of the array. if the items of the array are objets, you need to implements the Comparator interface on this Objets too.
you can get more implementation information on this link
BlackBerry JRE is 1.3 (like CLDC 1.1) and don't support generics, non-synchronized collections and other things from modern java world.
Sicne you're defining a comparator for a particular class you don't need (and can't use) generics. Your array comparator should cast the Object type parameters to their corresponding type before comparing in the compare method you override.
For example, your ArrayComparator should cast o1 and o2 to an array. In the future if you make a, say, UserDataComparator the compare method should cast the parameters to your UserData class type.
FYI: Blackberry's compiler (RAPC) supports up to java 1.4 AFAIK (check this) so Generics, Enums and other Java 1.5 and above features are not supported.
EDIT As other persons pointed (and for the sake of a complete answer) I was not specific enough on my anwer. I have edited this answer to reflect some crucial points related to your issue.
I apologize for such a long message in advance, but I'm trying for detail here...
I'm working on using bTouch to create a compiled dll for referencing the ArcGIS iOS SDK.
When running bTouch using :
/Developer/MonoTouch/usr/bin/btouch libArcGIS.cs
it returns the following error
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolygon.g.cs(39,31):
error CS0102: The type `IncidentReportApp.AGSMutablePolygon'
already contains a definition for `selAddPointToRing'
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolygon.g.cs(38,31):
(Location of the symbol related to previous error)
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolyline.g.cs(39,31): error CS0102:
The type `IncidentReportApp.AGSMutablePolyline'
already contains a definition for `selAddPointToPath'
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolyline.g.cs(38,31):
(Location of the symbol related to previous error)
Compilation failed: 2 error(s), 0 warnings
I checked my cs class and neither type is referenced\invoked. I'd like to understand why this message is occuring.
I have tried to use the instructions (and downloaded) code by Al Pascual at How to use the ArcGIS iPhone SDK with MonoTouch to call the Map View, but when attempting to launch the view with the code causes a crash. When I try to debug, it locks up when adding a mapping layer. I tested this with the MKMapView, but didn't experience the same behavior.
The error means that you defined more than one method mapping the same objective-C method.
Without the source, it is hard to diagnose.
I'm doing the same thing actually, I heavily modified the old "parser" library and am working on doing it now, hopefully dropping it in the public domain.
I'm seeing a similar (and probably related) problem in the ApiDefinition, there is a class AGSGPResultLayer that derives from AGSDynamicLayer. The AGSGPResultLayer overrides a property called Credential among other and since both are defining the same property.
How should over-riden properties be handled in bTouch? I'm guessing I'm missing something in the syntax.
Use the solution I provide with the correct bindings