Search Results

Search found 32346 results on 1294 pages for 'method overloading'.

Page 9/1294 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • How to find the first declaring method for a reference method

    - by Oliver Gierke
    Suppose you have a generic interface and an implementation: public interface MyInterface<T> { void foo(T param); } public class MyImplementation<T> implements MyInterface<T> { void foo(T param) { } } These two types are frework types. In the next step I want allow users to extend that interface as well as redeclare foo(T param) to maybe equip it with further annotations. public interface MyExtendedInterface extends MyInterface<Bar> { @Override void foo(Bar param); // Further declared methods } I create an AOP proxy for the extended interface and intercept especially the calls to furtherly declared methods. As foo(…) is no redeclared in MyExtendedInterface I cannot execute it by simply invoking MethodInvocation.proceed() as the instance of MyImplementation only implements MyInterface.foo(…) and not MyExtendedInterface.foo(…). So is there a way to get access to the method that declared a method initially? Regarding this example is there a way to find out that foo(Bar param) was declared in MyInterface originally and get access to the accoriding Method instance? I already tried to scan base class methods to match by name and parameter types but that doesn't work out as generics pop in and MyImplementation.getMethod("foo", Bar.class) obviously throws a NoSuchMethodException. I already know that MyExtendedInterface types MyInterface to Bar. So If I could create some kind of "typed view" on MyImplementation my math algorithm could work out actually.

    Read the article

  • Encapsulate update method inside of object or have method which accepts an object to update

    - by Tom
    Hi, I actually have 2 questions related to each other: I have an object (class) called, say MyClass which holds data from my database. Currently I have a list of these objects ( List < MyClass ) that resides in a singleton in a "communal area". I feel it's easier to manage the data this way and I fail to see how passing a class around from object to object is beneficial over a singleton (I would be happy if someone can tell me why). Anyway, the data may change in the database from outside my program and so I have to update the data every so often. To update the list of the MyClass I have a method called say, Update, written in another class which accepts a list of MyClass. This updates all the instances of MyClass in the list. However would it be better instead to encapulate the Update() method inside the MyClass object, so instead I would say foreach(MyClass obj in MyClassList) { obj.update(); } What is a better implementation and why? The update method requires a XML reader. I have written an XML reader class which is basically a wrapper over the standard XML reader the language natively provides which provides application specific data collection. Should the XML reader class be in anyway in the "inheritance path" of the MyClass object - the MyClass objects inherits from the XML reader because it uses a few methods. I can't see why it should. I don't like the idea of declaring an instance of the XML Reader class inside of MyClass and an MyClass object is meant to be a simple "record" from the database and I feel giving it loads of methods, other object instances is a bit messy. Perhaps my XML reader class should be static but C#'s native XMLReader isn't static.? Any comments would be greatly appreciated Thanks Thomas

    Read the article

  • Calling a class method within a method definition in the same class

    - by user1786288
    So I'm writing a program for an intro Java class. I'm defining a method to add two fractions together within the class Fraction. Fraction has 2 variables, numerator and denominator. Each of these variables has a setter and a getter. Anyway, I have a problem with my addition method, which is shown below. I've just sort of tried to implement it in a way that made sense, but I'm sure I did something with calling methods/using objects that doesn't work. public void add(Fraction fraction1, Fraction fraction2) { Fraction fraction3 = new Fraction(); int a = fraction1.getNumerator; int b = fraction1.getDenominator; int c = fraction2.getNumerator; int d = fraction2.getDenominator; fraction3.setNumerator((a * d) + (b * c)); fraction3.setDenominator(b * d); } I don't know if the problem is in the method definition, if I can use the object type that way, or if there's something else wrong. any help would be appreciated, and if I need to provide any information, I'll do so ASAP.

    Read the article

  • Overwrite HTTP method with JAX-RS

    - by deamon
    Today's browsers (or HTML < 5) only support HTTP GET and POST, but to communicate RESTful one need PUT and DELETE too. If the workaround should not be to use Ajax, something like a hidden form field is required to overwrite the actual HTTP method. Rails uses the following trick: <input name="_method" type="hidden" value="put" /> Is there a possibility to do something similar with JAX-RS?

    Read the article

  • Is factory method proper design for my problem?

    - by metdos
    Hello Everyone, here is my problem and I'm considering to use factory method in C++, what are your opinions ? There are a Base Class and a lot of Subclasses. I need to transfer objects on network via TCP. I will create objects in first side, and using this object I will create a byte array TCP message, and send it to other side. On the other side I will decompose TCP message, I will create object and I will add this object to a polymorphic queue.

    Read the article

  • What is wrong with this c# method?

    - by bala3569
    I use this method to get file extension, public string ReturnExtension(string fileExtension) { switch (fileExtension) { case ".doc": case ".docx": return "application/ms-word"; } } When i compile it i got the error BaseClass.ReturnExtension(string)': not all code paths return a value.. Any suggestion...

    Read the article

  • Using the masters method

    - by Roarke
    On my midterm I had the problem: t(n) = 8T(n/2) +n^3 and I am supposed to find its big theta notation using either the masters or alternative method. So what i did was a = 8, b = 2 k = 3 log8 (base 2) = 3 = k therefore, T(n) is big theta n^3. I got 1/3 points so i must be wrong. What did I do wrong?

    Read the article

  • get request.session from a model method in django

    - by dotty
    Hay, is it possible to a get a request.session value from a model method in django? Here is what i need def html(self): Template = loader.get_template("inclusions/Template") return Template.render(Context({ 'user_id':request.session['user'].id })) user_id would be request.session['user'].id

    Read the article

  • Calling javascript method from from inside object

    - by John
    I am struggling with methods in JavaScript. obj = function(){ this.getMail = function getMail (){ } //Here I would like to run the get mail once but this.getMail() or getMail() wont work } var mail = new obj(); mail.getMail(); How do I make the method in a way that I can run it both inside the object and from the outside Thanks

    Read the article

  • Checking method visibility in PHP

    - by phobia
    Is there any way of checking if a class method has been declared as private or public? I'm working on a controller where the url is mapped to methods in the class, and I only want to trigger the methods if they are defined as public.

    Read the article

  • ocjective-c Obtain return value from public method

    - by Felix
    I'm pretty new to objective-C (and C in general) and iPhone development and am coming from the java island, so there are some fundamentals that are quite tough to learn for me. I'm diving right into iOS5 and want to use storyboards. For now I am trying to setup a list in a UITableViewController that will be filled with values returned by a web service in the future. For now, I just want to generate some mock objects and show their names in the list to be able to proceed. Coming from java, my first approach would be to create a new Class that provides a global accessible method to generate some objects for my list: #import <Foundation/Foundation.h> @interface MockObjectGenerator : NSObject +(NSMutableArray *) createAndGetMockProjects; @end Implementation is... #import "MockObjectGenerator.h" // Custom object with some fields #import "Project.h" @implementation MockObjectGenerator + (NSMutableArray *) createAndGetMockObjects { NSMutableArray *mockProjects = [NSMutableArray alloc]; Project *project1 = [Project alloc]; Project *project2 = [Project alloc]; Project *project3 = [Project alloc]; project1.name = @"Project 1"; project2.name = @"Project 2"; project3.name = @"Project 3"; [mockProjects addObject:project1]; [mockProjects addObject:project2]; [mockProjects addObject:project3]; } And here is my ProjectTable.h that is supposed to control my ListView #import <UIKit/UIKit.h> @interface ProjectsTable : UITableViewController @property (strong, nonatomic) NSMutableArray *projectsList; @end And finally ProjectTable.m #import "ProjectsTable.h" #import "Project.h" #import "MockObjectGenerator.h" @interface ProjectsTable { @synthesize projectsList = _projectsList; -(id)initWithStyle:(UITableViewStyle:style { self = [super initWithStyle:style]; if (self) { _projectsList = [[MockObjectGenerator createAndGetMockObjects] copy]; } return self; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // only one section for all return 1; - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"%d entries in list", _projectsList.count); return _projectsList.count; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // the identifier of the lists prototype cell is set to this string value static NSString *CellIdentifier = @"projectCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; Project *project = [_projectsList objectAtIndex:indexPath.row]; cell.textLabel.text = project.name } So while I think everything is correctly set, I expect the tableView to show my three mock objects in its rows. But it stays empty and the NSLog method prints "0 entries in list" into the console. So what am I doing wrong? Any help is appreciated. Best regards Felix

    Read the article

  • method implementation for this case in Java

    - by Thomas
    Hello, I just saw a code snippet like this: private static class DefaultErrorHandler<RT> implements ErrorHandler<RT> { public RT handle(Object[] params, Throwable e) { return Exceptions.throwUncheckedException(e); } Now I am wondering what the static method "throwUncheckedException (Throwable e)" would return exactly and how it might be implemented regarding the generics. Can anybody give me an example ?

    Read the article

  • When is a parameterized method call useful?

    - by johann-christoph-jacob
    A Java method call may be parameterized like in the following code: class Test { <T> void test() { } public static void main(String[] args) { new Test().<Object>test(); // ^^^^^^^^ } } I found out this is possible from the Eclipse Java Formatter settings dialog and wondered if there are any cases where this is useful or required.

    Read the article

  • How to use method hiding (new) with generic constrained class

    - by ongle
    I have a container class that has a generic parameter which is constrained to some base class. The type supplied to the generic is a sub of the base class constraint. The sub class uses method hiding (new) to change the behavior of a method from the base class (no, I can't make it virtual as it is not my code). My problem is that the 'new' methods do not get called, the compiler seems to consider the supplied type to be the base class, not the sub, as if I had upcast it to the base. Clearly I am misunderstanding something fundamental here. I thought that the generic where T: xxx was a constraint, not an upcast type. This sample code basically demonstrates what I'm talking about. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GenericPartialTest { class ContextBase { public string GetValue() { return "I am Context Base: " + this.GetType().Name; } public string GetOtherValue() { return "I am Context Base: " + this.GetType().Name; } } partial class ContextSub : ContextBase { public new string GetValue() { return "I am Context Sub: " + this.GetType().Name; } } partial class ContextSub { public new string GetOtherValue() { return "I am Context Sub: " + this.GetType().Name; } } class Container<T> where T: ContextBase, new() { private T _context = new T(); public string GetValue() { return this._context.GetValue(); } public string GetOtherValue() { return this._context.GetOtherValue(); } } class Program { static void Main(string[] args) { Console.WriteLine("Simple"); ContextBase myBase = new ContextBase(); ContextSub mySub = new ContextSub(); Console.WriteLine(myBase.GetValue()); Console.WriteLine(myBase.GetOtherValue()); Console.WriteLine(mySub.GetValue()); Console.WriteLine(mySub.GetOtherValue()); Console.WriteLine("Generic Container"); Container<ContextBase> myContainerBase = new Container<ContextBase>(); Container<ContextSub> myContainerSub = new Container<ContextSub>(); Console.WriteLine(myContainerBase.GetValue()); Console.WriteLine(myContainerBase.GetOtherValue()); Console.WriteLine(myContainerSub.GetValue()); Console.WriteLine(myContainerSub.GetOtherValue()); Console.ReadKey(); } } }

    Read the article

  • How to invoke a method of js object after invoking another method?

    - by Unitpage
    I often saw this code in jQuery. $('div').action1().delay(miliseconds).action2(); I could realize it in one level action in the following code. function $(id) { var $ = document.getElementById(id); $.action1 = function() { }; return $; } How to write the method delay() and action2() so that I could use them this way? $('div').action1().delay(miliseconds).action2();

    Read the article

  • Should we rename overloaded methods?

    - by Mik378
    Assume an interface containing these methods : Car find(long id); List<Car> find(String model); Is it better to rename them like this? Car findById(long id); List findByModel(String model); Indeed, any developer who use this API won't need to look at the interface for knowing possible arguments of initial find() methods. So my question is more general : What is the benefit of using overloaded methods in code since it reduce readability?

    Read the article

  • Rhino Mocks verify a private method is called from a public method

    - by slowcelica
    I have been trying to figure this one out, how do i test that a private method is called with rhino mocks with in the class that I am testing. So my class would be something like this. Public class Foo { public bool DoSomething() { if(somevalue) { //DoSomething; } else { ReportFailure("Failure"); } } private void ReportFailure(string message) { //DoSomeStuff; } } So my unit test is on class Foo and method DoSomething() I want to check and make sure that a certain message is passed to ReportFailure if somevalue is false, using rhino mocks.

    Read the article

  • Qt undocumented method setSharable

    - by soxs060389
    I stumbled about a method which seems to be present in all DataObjects like QList, QQueue, QHash... I even investigated so far i can see the source code of it, which is inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } in qlist.h (lines 117) but what effect does it have on the QList, QQueue, QHash... ? And is it in any way related to threading? (which sounds reasonable) Thanks for any answer, and please only answer if you got actual knowledge.

    Read the article

  • Ruby delete method (string manipulation)

    - by brianheys
    I'm new to Ruby, and have been working my way through Mr Neighborly's Humble Little Ruby Guide. There have been a few typos in the code examples along the way, but I've always managed to work out what's wrong and subsequently fix it - until now! This is really basic, but I can't get the following example to work on Mac OS X (Snow Leopard): gone = "Got gone fool!" puts "Original: " + gone gone.delete!("o", "r-v") puts "deleted: " + gone Output I'm expecting is: Original: Got gone fool! deleted: G gne fl! Output I actually get is: Original: Got gone fool! deleted: Got gone fool! The delete! method doesn't seem to have had any effect. Can anyone shed any light on what's going wrong here? :-\

    Read the article

  • Naming Suggestions For A Function Providing Chaining In A Different Way

    - by sid3k
    I've coded an experimental function which makes passed objects chainable by using high order functions. It's name is "chain" for now, and here is a usage example; chain("Hello World") (print) // evaluates print function by passing "Hello World" object. (console.log,"Optional","Parameters") (returnfrom) // returns "Hello World" It looks lispy but behaves very different since it's coded in a C based language, I don't know if there is a name for this idiom and I couldn't any name more suitable than "chain". Any ideas, suggestions?

    Read the article

  • Define Instance Variable Outside of Method Defenition (ruby)

    - by Ell
    Hi all, I am developing (well, trying to at least) a Game framework for the Ruby Gosu library. I have made a basic event system wherebye each Blocks::Event has a list of handlers and when the event is fired the methods are called. At the moment the way to implement an event is as follows: class TestClass attr_accessor :on_close def initialize @on_close = Blocks::Event.new end def close @on_close.fire(self, Blocks::OnCloseArgs.new) end end But this method of implementing events seems rather long, my question is, how can I make a way so that when one wants an event in a class, they can just do this class TestClass event :on_close def close @on_close.fire(self, Blocks::OnCloseArgs.new) end end Thanks in advance, ell.

    Read the article

  • c# Generic overloaded method dispatching ambiguous

    - by sebgod
    Hello, I just hit a situation where a method dispatch was ambiguous and wondered if anyone could explain on what basis the compiler (.NET 4.0.30319) chooses what overload to call interface IfaceA { } interface IfaceB<T> { void Add(IfaceA a); T Add(T t); } class ConcreteA : IfaceA { } class abstract BaseClassB<T> : IfaceB<T> { public virtual T Add(T t) { ... } public virtual void Add(IfaceA a) { ... } } class ConcreteB : BaseClassB<IfaceA> { // does not override one of the relevant methods } void code() { var concreteB = new ConcreteB(); // it will call void Add(IfaceA a) concreteB.Add(new ConcreteA()); } In any case, why does the compiler not warn me or even why does it compile? Thank you very much for any answers.

    Read the article

  • how do I send stuff to method using the JQuery Ajax method

    - by nisardotnet
    $.ajax({ type: "POST", url: "WebService.asmx/AddVisitor", data: "{'fname':'dave', 'lname':'ward'}", contentType: "application/json; charset=utf-8", dataType: "json" }); I have an Asp.Net WebMethod that takes a firstName, lastName.....as a parameter, how do I send that stuff to that method using the JQuery Ajax method. if i hardcode the above it works without any problem but if i pass dynamic it fails var firstName = $("[id$='txtFirstName']"); var lastName = $("[id$='txtLastName']"); //data: "{'firstName':'Chris','lastName':'Brandsma'}"<br> data: "{'firstname':'" + escape(firstName.val()) + "','lastName':'" + escape(lastName.val()) + "'}", my WebMethod looks like this [WebMethod] public bool AddVisitor(string firstName, string lastName) { return true; } what wrong here? i have tried with eval and escape none of that works. Thanks for any help.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >