w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Scala generic method - No ClassTag available for T
To instantiate an array in a generic context (instantiating an array of T where T is a type parameter), scala needs at runtime to have information about T, in the form of an implicit value of type ClassTag[T]. Concretely, you just need to require from the caller of your method to (implicitly) pass this ClassTag value, which can conveniently be done using a context bound: def foo[T:ClassTag](count: Int, value: T): Array[T] = Array.fill[T](count)(value) For a (torough) description of this situation, see this document: http://docs.scala-lang.org/sips/completed/scala-2-8-arrays.html (To put it shortly, ClassTags are the reworked implementation of ClassManifests, so the rationale remains)

Categories : Scala

Object of a class as return type of method of another class
class Node {...} Node; Here you're creating an instance of Node named Node. Then inside your function prototypes/definitions you use Node as if it were a type, when its not. Maybe you meant to typedef the class: typedef class Node {...} Node; But you don't even need a typedef here in C++ because class names don't require a prefix of class or struct. Just use the class name: class Name {...};

Categories : C++

How to use return value of a method in a another class in android
Take object of that class in which you defined your method into your second activity and use like below code: testing t1 = new testing(); double returnval = t1.match_eye(yourarea, youmTemplate,yourtype); System.out.println(returnval); For sending value using Intent: Intent i = new Intent(context,MainActivity.class) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra("var", returnval) context.startActivity(i);

Categories : Java

Return value in a class from another class and method
You must specify what you want to return in the definition of the method and actually return a value using the keyword return: public int sum(int a, int b){ int result = a + b; return result; } You've declared Mean() as void public void Mean(Bitmap image) and thus it returns no value. Also, you can only return 1 variable so you should either put those 3 values in some sort of array or create a new class and encapsulate the variables inside an object. Here is an example: public class MeanResult(){ private double meanR[]=new double[320]; private double meanG[]=new double[320]; private double meanB[]=new double[320]; //Maybe declare more stuff here public MeanResult(Bitmap image){ //... code n stuff here to calculate width, height and pixel } public double getMeanR(){ return this

Categories : Java

If a class inherits a method does calling that method on that class point to the super class or does it make a local copy within the child class?
It will follow the way you have it currently written: -> New object of class B -> Call method One on this object -> First line calls supermethod, proceed to execute it -> Second line prints out after that Your code doesn't compile at all though, you might want to clear that up. What's keeping you from testing this yourself? Here's the new situation as you described it. Everything still works as expected, you just add a layer. public class C { public void test() { System.out.println("Inside C"); } } public class B extends C { public void test() { super.test(); System.out.println("Inside B"); } } public class A extends B { public static void main(String[] args) { A obj = new A(); obj.test(); } } Out

Categories : Java

php pdo in class + best method to display return array
I think you're missing the $this-> part. So basically you're creating a local variable inside the method named unapprovedProfilePhotosArray which disappears when the method finishes. If you want that array to stay in the property, then you should use $this->, which is the proper way to access that property. ... $pds=$users->pdo->prepare($sql); $pds->execute(array()); $rows=$pds->fetchAll(); $this->unapprovedProfilePhotosArray = $rows; ...

Categories : PHP

Is it possible to use css wildcard class selector where there are multiple class values?
You were using an incorrect selector - a [class] is all anchors with a class as a descendant. Basically, any element descending from an <a>, which starts with or contains the class icon- will be targeted. What you want is to select all anchors starting with or containing that class themselves - a[class]: a[class^="icon-"], a[class*=" icon-"] { text-decoration: none; color: #1BA1E2; } jsFiddle example here.

Categories : CSS

How to get rid of wildcard return type with generics in Java?
Change your GeneratorClient declaration to this: public class GeneratorClient<T extends Base> implements IClient<T> { private final Class<T> clazz; // etc This should do it. EDIT Since you only know the class at runtime, add a static factory method to build your GeneratorClient: public static <T extends Base> GeneratorClient<T> forClass(final Class<T>) { return new GeneratorClient<T>(whatever, args, are, needed, if, any); } In code: final GeneratorClient<MyClass> = GeneratorClient.forClass(MyClass.class);

Categories : Java

Return child class from parent's static method
So, I will post my answer here. In my opinion overriding static function createFromFormat is the best way to deal with your problem. Because: You code will stay clean (without any unnecessary call_user_func) It is just right that you override parent class methods and keep the class logics inside class. Your class SerialDateTime will be futher reusable. (if you want to import only class code) It is not necessary though to override all methods (unless you implement an interface). Override just only those you need.

Categories : PHP

How do you return a struct like CLLocationCoordinate2D from a class method properly?
I'm not totally getting the point why you do not want to import CoreLocation, but CLLocationCoordinate2D is declared in CoreLocation.h. I'm not aware about a method like @class for struct and I don't think it exists since struct are C types. What you can do is create your own class that wraps the CLLocationCoordinate2D or return the NSValue from it, or (why not?) a dictionary.

Categories : IOS

Can I use a custom class method on NSArray to return a constant?
In general, there can be very good uses for adding class methods to foundation classes via categories. But in this case, I would actually stick with arrayOfTeamNames being part of MyConstants. The fact that Team Names is an NSArray isn't as important as the fact that it's a constant for your application. If the values defined in MyConstants are very diverse and unrelated, or if there are only a couple of them, then I would consider just getting rid of MyConstants as a class and using categories or even just externs, e.g. extern NSArray * const BPAllTeamNames.

Categories : IOS

Difference between using a method in a class to return a value and referencing the exact value itself
If guiWait is a public boolean, there is no point in having a "getter" method for it. If it were private or protected, then it'd be a different story. The private-getter method is more flexible because you can change the implementation of the "getting" of that variable, and add checks or whatever inside the method. Private getters/setters also make things clearer and establish which things should be seen by other classes and which are only meant to be used inside a single class they are apart of. If you find you do need a getter for a specific member variable (need some kind of verification or checking), which is very common, then it would be inconsistent to do it just for that variable.

Categories : Java

Same method with different return types in abstract class and interface
If the method in abstract class is abstract too, you will have to provide its implementation in the first concrete class it extends.Additionally, you will have to provide implementation of interface. If both the methods differ only in return type, the concrete class will have overloaded methods which differ only in return type. And we cant have overloaded methods which differ only in return type,hence the error. interface io { public void show(); } abstract class Demo { abstract int show(); } class Test extends Demo implements io { void show () //Overloaded method based on return type, Error { } int show() //Error { return 1; } public static void main (String args[]) { } }

Categories : Java

return vb variant by reference from c# method in c# COM Visible class
Feel free to experiment: do RegAsm.exe /tlb to generate a .TLB file, then use OleView.exe to view it. For a method signature like yours: public void DoStuff(string someString, int someInt, ref object refLong, ref object refString) you should see the corresponding interface method like this: HRESULT DoStuff([in] BSTR someString, [in] long someInt, [in, out] VARIANT* refLong [in, out] VARIANT* refString)

Categories : C#

No ClassTag available for T -- not for Array
Though you omitted the place where the errors took place, I'm guessing they are happening at Props. It is probably the case that Props take an implicit ClassTag as a parameter, particularly since it doesn't take any other parameter. And though a ClassTag is used by array creation, it can also be used for other things, such as getting a Class that can then be used to instantiate classes by reflection, or as a reference when comparing instances received. To solve it, declare AkkaBaseClass like this: import scala.reflect.ClassTag abstract class AkkaBaseClass[T <: AkkaClass1 : ClassTag, U <: Loger : ClassTag] extends Actor {

Categories : Scala

Place sql method in seperate class and return multiple strings
You ought to avoid the use of out parameters in your method definition. They are not being used as you are returning a concatenation of the account and account_printed strings anyway, so your method signature should look like this: public string SelectConsHead(string sReference) ...and therefore you need to declare your local string variables, e.g: var sAccount_Printed = ""; var sAccount = ""; You should also consider why you are prefixing string variable names with 's', as this is considered by many to be bad practice. For Microsoft's coding guidelines, see this link: http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx If your class is called DataManager, you need to instantiate the class in order to call your method (as it is not static). For example: var sReference =

Categories : C#

Search Strings for Wildcard in python and return position of match
I'm not very experienced in Python, but I think you can do something like this: import re strings = [['ID#1','NTGSLTKNASMNLTQRSNQT'],['ID#2','NLSHTNWEUWBNTTDKWODNUT']] def findpos(s): return [s[0], [m.start() + 1 for m in re.finditer('N[^P][ST]',s[1])]] return map(findpos, strings) // [['ID#1', [8, 12, 18]], ['ID#2', [1, 12, 20]]] or even more simply, just: [[s[0], [m.start() + 1 for m in re.finditer('N[^P][ST]',s[1])]] for s in strings]

Categories : Python

Is it possible in Java to Invoke another class' main method and return to the invoking code?
Your code already nearly does it - it's just not passing in the arguments: String[] args = {}; A.main(args); The main method is only "special" in terms of it being treated as an entry point. It's otherwise a perfectly normal method which can be called from other code with no problems. Of course you may run into problems if it's written in a way which expects it only to be called as an entry point (e.g. if it uses System.exit) but from a language perspective it's fine.

Categories : Java

Is there a wildcard for the .Take method in LINQ?
You could separate it to a separate call based on your flag: IEnumerable<RatingAndProducts> ratingsToPick = context.RatingAndProducts .OrderByDescending(c => c.WeightedRating); if (!takeAll) ratingsToPick = ratingsToPick.Take(pAmmount); var results = ratingsToPick.ToList(); If you don't include the Take, then it will simply take everything. Note that you may need to type your original query as IEnumerable<MyType> as OrderByDescending returns an IOrderedEnumerable and won't be reassignable from the Take call. (or you can simply work around this as appropriate based on your actual code) Also, as @Rene147 pointed out, you should move your ToList to the end otherwise it will retrieve all items from the database every time and the OrderByDescending and Take are the

Categories : C#

Searching a listbox using a bool method from another class. Getting 'not all code paths return a value'. Any idea why?
If the if statement returns true, but the loop has nothing to iterate over, your method will never return anything. This could happen if another thread modifies the list. You should get rid of the outer if / else entirely and simply return false after the loop. Also, you don't want to return false in the inner else. Right now, if the first product doesn't match, your loop will stop immediately, without checking the other items.

Categories : C#

Javascript: Inherit method from base class and return the subclass's private variable
privateVar is a local variable of BaseClass. It cannot be inherited or changed by the subclass. You can encapsulate the parent and subclass in the same scope like so: (function(){ var privateVar = 7500; function BaseClass (arg1,arg2,arg3) { //constructor code here then - this.getPrivateVar = function() { return privateVar; }; } function SubClass (arg1,arg2,arg3,privateVar) { //constructor code here then - } SubClass.prototype = new BaseClass(); return SubClass; })();

Categories : Javascript

Polymorphic instantiation in Scala using TypeTag and ClassTag
TypeTag is not yet a replacement for Manifest because it's a part of experimental and unstable Scala reflection. You definitely shouldn't use it for production as of now. For the use case you showed, where only runtime class is needed (not full type information with generics etc.), Scala 2.10 introduced ClassTag, which you can use like this: def newInstance[T: ClassTag] = implicitly[ClassTag[T]].runtimeClass.newInstance.asInstanceOf[T] or: def newInstance[T](implicit ct: ClassTag[T]) = ct.runtimeClass.newInstance.asInstanceOf[T] Anyway, Manifest isn't deprecated yet, so I guess you can still use it. EDIT: Using TypeTag to achieve the same: import scala.reflect.runtime.universe._ def newInstance[T: TypeTag] = { val clazz = typeTag[T].mirror.runtimeClass(typeOf[T]) clazz.n

Categories : Scala

How make java.lang.reflect.Method.getReturnType return void.class with EasyMock?
The answer is: EasyMock.expect(method.getReturnType()).andReturn((Class) void.class); But there is EasyMock run time errors because java.lang.reflection.Method is final.

Categories : Java

what is difference between "update" method of Session class and "executeupdate" method of Query class in hibernate, when which method use?
In short: Session.update() is used to update a single mapped entity; with Query.executeupdate() you can perform custom delete/update statement (written is HQL or pure SQL) and get as result the updated/deleted entities count. Which is the right method depends which is your need: with executeupdate() you can delete/update an arbitrary number of objects based on a query, with update() you can only update one single object at time.

Categories : Java

why the 'unknown method' error in xpath wildcard search
Using the XPath higher functions Microsoft developed their XML parser before W3C finalised XPath standards, so it was based on their own system called XSL Pattern. (Microsoft was involved in defining the XPath standards so XSL Pattern is similar and much of it, though not all, became part of XPath.) For backwards compatibility, Microsoft’s XML parser (even the latest one) uses XSL Pattern by default. XSL Pattern doesn’t include the functions such as ‘contains’, which is why the ‘unknown method’ error occurs. To fix this, we need to tell the DOMDocument object (docXml) to use XPath instead: docXml.setProperty "SelectionLanguage", "XPath" Namespaces However, this creates another problem, because XPath is more sensitive to namespaces. The path //event, for example, finds all de

Categories : Xml

Java Generics wildcard extends final class
The compiler doesn't really take note of that fact, because it doesn't matter. Strings are still allowed in the list, and in the final product, the possibility of anything extending String is not found. After erasure, it comes out like this: public void addStrings(List list) As you can see, there is now no suggestions of a class extending String. If you do create a class extending String, that will be itself a compile error. There's no need for javac to worry about that.

Categories : Java

Mock static method Activator.CreateInstance to return a mock of another class
Well, I am tempted to say that this is not something you need to mock as it should be trusted to be under test, but I guess if the type is from an external source library, then you might have problems...that being said, the only way you can achieve this is to wrap Activator so that it is not a static class. Something like this: public ActivatorWrapper { public virtual object CreateInstance(Type type) { return Activator.CreateInstance(type); } }

Categories : C#

How to declare an inter-type method with return type of every object's class?
Try this: aspect MyAspect { public S MyInterface<S>.getMyself() { return (S) this; } } interface MyInterface<T extends MyInterface<T>> { } class MyClassOne implements MyInterface<MyClassOne> {} class MyClassTwo implements MyInterface<MyClassTwo> {} class Main { public static void main(String[] args) { MyClassOne aClassOne = new MyClassOne().getMyself(); MyClassTwo aClassTwo = new MyClassTwo().getMyself(); MyClassOne errorClassOne = new MyClassTwo().getMyself(); // compile error MyClassTwo errorClassTwo = new MyClassOne().getMyself(); // compile error } } Fun with generics! Answer is straight forward, I think, but let me know if this is confusing for you.

Categories : Java

Query on Junit @parameters method's return type and the test class constructor argument type
As you suggested the values are being casted. The casting is actually done by the Java reflection API, specifically: Constructor.newInstance(Object...). If you're curious, the above method is invoked by JUnit on line 186, here (JUnit v4.11 source).

Categories : Java

How to call a templated method in a derived class that implements a pure virtual method in the base class?
This is a case where the dreaded diamond (virtual inheritance and multiple inheritance) can help you. You can use a template proxy class that inherits virtually from your GenericFunction to be your common implementation. Then, use multiple inheritance on the specific implementations you want to create your SpecificFunction. class ProxyState; template <typename T> class ProxyFunction : public virtual GenericFunction { public: ProxyFunction() : GenericFunction() {}; virtual ProxyState * state () { return 0; } void Iterate (T *ps, unsigned cs) { // Do function operations on block of samples, using state() // if necessary std::cout << __PRETTY_FUNCTION__ << " "; } }; class SpecificFunction : public ProxyFunction<short>, pu

Categories : C++

Why does calling a method in my derived class call the base class method?
The compiler does this because it doesn't know that it is a Teacher. All it knows is that it is a Person or something derived from it. So all it can do is call the Person.ShowInfo() method.

Categories : C#

How do I get .htaccess to redirect from wildcard subdomain page to wildcard subdomain folder
Add this to the htaccess file in your document root(s): RedirectMatch 301 ^/([^/]+).php$ /$1/ You'll most likely need that trailing slash because if it's redirecting you to a directory, mod_dir will redirect again in order to add the trailing slash. EDIT: To exclude, you'll have to use mod_rewrite: RewriteEngine On RewriteCond %{REQUEST_URI} !index.php RewriteRule ^/?([^/]+).php$ /$1/ [L,R=301]

Categories : PHP

In java, if I call, from a subclass, a superclass method that calls an overriden method, which class' method will be called?
Because the method MyPrMethod() is overridden in the subclass, the subclass implementation will be called. The actual method that gets called depends on the object on which it gets called.

Categories : Java

"Method must have a return type" and "return must not be followed by an object expression"
You would need to change the declaration to return an Exception: public static Exception LogMessage(Exception ex) { Trace.WriteLine(ex.ToString()); return ex; } Note that, depending on usage, it might make sense to allow this to be a generic method: public static T LogMessage<T>(T ex) where T : Exception { Trace.WriteLine(ex.ToString()); return ex; } This would allow you to use the resulting exception in a strongly typed manner. Alternatively, you could just not return the exception, since Logging shouldn't need to return an exception in any case: public static void LogMessage(Exception ex) { Trace.WriteLine(ex.ToString()); }

Categories : C#

Call method in abstract class after method of extending class?
No there isn't I'm afraid. If you're hoping to achieve 'post execution hook' style functionality, you could design your class to implement the __call() magic method. For example: <?php abstract class AbstractTest { protected function myMethod() { echo 'Bar'; } } class Test extends AbstractTest { public function __call($methodName, $args) { call_user_func_array(array($this, $methodName), $args); call_user_func_array(array('parent', $methodName), $args); } protected function myMethod() { echo 'Foo'; } } $test = new Test(); // Will output 'FooBar' $test->myMethod(); By declaring myMethod() to be protected, you can't call it publicly. It therefore gets 'intercepted' by __call() method which calls it in it's own context and then that of its' pa

Categories : PHP

alternative to base keyword in static method of derived class to call overrided method of base class
A static method does not belong to an instance, hence it has no base. You can only say A.display() if A.display() is also a static method. You can also say new A().display() to discard the instance after calling display().

Categories : C#

Return multiple results from class with return instead echo?
Just load everything into an array and return the array. Keep the output formatting out of this class and leave that up to the whatever is calling this class. $return_array = array(); while ($row = $r->fetch_assoc()) { $return_array[]['title'] = $row['title']; } return $return_array;

Categories : PHP

Return a reference by a class function and return a whole object in c++?
First, the usual convention in C++ is to pass class type arguments as references to const. There are clearly exceptions (predicate objects or iterators in the standard library), but in application level code, passing a class type by reference to const is ubiquitous enough to justify a comment: Vector Vector::operator+( Vector const& rhs ) const { // ... } Or more likely: Vector operator+( Vector const& lhs, Vector const& rhs ) { Vector results( lhs ); results += rhs; return results; } Another widespread convention is to make such binary operators free functions, so that both the left and right arguments ar treated in the same fashion. And to implement them in terms of =, so as to ensure that = and have the desired relation. For operators which modify

Categories : C++

PHP: differences in calling a method from a child class through parent::method() vs $this->method()
self::, parent:: and static:: are special cases. They always act as if you'd do a non-static call and support also static method calls without throwing an E_STRICT. You will only have problems when you use the class' names instead of those relative identifiers. So what will work is: class x { public function n() { echo "n"; } } class y extends x { public function f() { parent::n(); } } $o = new y; $o->f(); and class x { public static function n() { echo "n"; } } class y extends x { public function f() { parent::n(); } } $o = new y; $o->f(); and class x { public static $prop = "n"; } class y extends x { public function f() { echo parent::$prop; } } $o = new y; $o->f(); But what won't work is: class x { public $prop = "n"; } class y extends x { public function f() { echo

Categories : PHP

How to use a variable defined inside a method use outside the method in another method on the same Class in java
If you want to send a hi message after the connection is established, you should put the line in the chatConnected() callback method instead. The reason is, that you might otherwise try to send a message even if you are not connected. I don't know the Omegle API, but I assume that's the reason why you have callback methods in OmegleEventAdaptor. Furthermore, if you want to send messages outside this callback class, you should assign the session to an instance field of MainActivity: @Override public void chatConnected(OmegleSession session) { System.out.println("You are now talking to a random stranger!"); session.send("hi", true); MainActivity.this.session = session; } Then you can simply access the session object from your MainActivity, e.g. if a button is clicked.

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.