Search Results

Search found 32130 results on 1286 pages for 'method chaining'.

Page 6/1286 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • 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

  • Segfault when calling a method c++

    - by shuttle87
    I am fairly new to c++ and I am a bit stumped by this problem. I am trying to assign a variable from a call to a method in another class but it always segfaults. My code compiles with no warnings and I have checked that all variables are correct in gdb but the function call itself seems to cause a segfault. The code I am using is roughly like the following: class History{ public: bool test_history(); }; bool History::test_history(){ std::cout<<"test"; //this line never gets executed //more code goes in here return true; } class Game{ private: bool some_function(); public: History game_actions_history; bool local_variable; }; bool Game::some_function(){ local_variable = game_actions_history.test_history(); if (local_variable == true){ return true; } else{ return false; } } Any tips or advice is greatly appreciated!

    Read the article

  • How to replace a codebehind method with an aspx method using ternary operator

    - by user466663
    I have an asp:hyperlink control as part of a gridview template. The code in the aspx page is given below: asp:HyperLink runat="server" ID="lnkEdit" ToolTip="Edit article" NavigateUrl='<%# GetUrl(Eval("ID").ToString(), Eval("CategoryID").ToString()) %' ImageUrl="~/Images/Edit.gif" The NavigateUrl value is obtained from the codebehind method GetUrl(string, string). The code works fine and is as follows: protected string GetUrl(string id, string categoryID) { var CategoryID = string.Empty; if (!String.IsNullOrEmpty(Request.QueryString["CatID"])) { CategoryID = Request.QueryString["CatID"].ToString(); } else if (!String.IsNullOrEmpty(categoryID)) { CategoryID = categoryID; } return "~/TBSArticles/WriteOrEditArticle.aspx?ID=" + id + "&CatID=" + CategoryID; } I want to replace the code behind method by using a ternary operator within the aspx page. I tried something like below, but didn't work: asp:HyperLink runat="server" ID="lnkEdit" ToolTip="Edit article" NavigateUrl='<%# "~/TBSArticles/WriteOrEditArticle.aspx?ID=" + Eval("ID") + "&CatID=" + Eval(this.Request.QueryString["CatID"].ToString()) != ""? this.Request.QueryString["CatID"] : Eval("CategoryID")) %' ImageUrl="~/Images/Edit.gif" Any help will be greatly appreciated. Thanks

    Read the article

  • Method overloading in groovy

    - by slojo
    I am trying to take advantage of the convenience of groovy's scripting syntax to assign properties, but having trouble with a specific case. I must be missing something simple here. I define class A, B, C as so: class A { A() { println "Constructed class A!" } } class B { B() { println "Constructed class B!" } } class C { private member C() { println "Constructed class C!" } def setMember(A a) { println "Called setMember(A)!" member = a } def setMember(B b) { println "Called setMember(B)!" member = b } } And then try the following calls in a script: c = new C() c.setMember(new A()) // works c.member = new A() // works c.setMember(new B()) // works c.member = new B() // doesn't work! The last assignment results in an error: 'Cannot cast object of class B to class A". Why doesn't it call the proper setMember method for class B like it does for class A?

    Read the article

  • Reference to an instance method of a particular object

    - by Andrey
    In the following code, if i try to pass method reference using the class name, works. But passing the reference variable compiler gives an error, i do not understand why? public class User { private String name; public User(String name) { this.name = name; } public void printName() { System.out.println(name); } } public class Main { public static void main(String[] args) { User u1 = new User("AAA"); User u2 = new User("BBB"); User u3 = new User("ZZZ"); List<User> userList = Arrays.asList(u1, u2, u3); userList.forEach(User::printName); // works userList.forEach(u1::printName); // compile error } } Thanks,

    Read the article

  • Why doesn't this method print its text? (java)

    - by David
    here's the method: public static int chooseStrat () { String[] strats = new String[1] ; strats[0] = "0 - Blob" ; int n ; boolean a = false ; while (a == false) ; { System.out.println ("Which strategy should the AI use?(#)") ; printArrayS (strats) ; n = getInt () ; System.out.println ("you selected "+n+"."+" are you sure you want the computer to use the "+ strats[n]+ " ?(Y/N)") ; String c = getIns () ; while ((((!( (c.equals ("y")) || (c.equals ("Y")) )) && (!( (c.equals ("n")) || (c.equals ("N")) ) ) ))) ; { System.out.println ("try again") ; c = getIns () ; } if ( (c.equals ("Y")) || (c.equals ("y")) ) a = true ; } return n ; } When i run this it never prints "Which strategy should the AI use?(#)" it just tries to get an entry from the keyboard. why does it do this?

    Read the article

  • Factory Method Implementation

    - by cedar715
    I was going through the 'Factory method' pages in SO and had come across this link. And this comment. The example looked as a variant and thought to implement in its original way: to defer instantiation to subclasses... Here is my attempt. Does the following code implements the Factory pattern of the example specified in the link? Please validate and suggest if this has to undergo any re-factoring. public class ScheduleTypeFactoryImpl implements ScheduleTypeFactory { @Override public IScheduleItem createLinearScheduleItem() { return new LinearScheduleItem(); } @Override public IScheduleItem createVODScheduleItem() { return new VODScheduleItem(); } } public class UseScheduleTypeFactory { public enum ScheduleTypeEnum { CableOnDemandScheduleTypeID, BroadbandScheduleTypeID, LinearCableScheduleTypeID, MobileLinearScheduleTypeID } public static IScheduleItem getScheduleItem(ScheduleTypeEnum scheduleType) { IScheduleItem scheduleItem = null; ScheduleTypeFactory scheduleTypeFactory = new ScheduleTypeFactoryImpl(); switch (scheduleType) { case CableOnDemandScheduleTypeID: scheduleItem = scheduleTypeFactory.createVODScheduleItem(); break; case BroadbandScheduleTypeID: scheduleItem = scheduleTypeFactory.createVODScheduleItem(); break; case LinearCableScheduleTypeID: scheduleItem = scheduleTypeFactory.createLinearScheduleItem(); break; case MobileLinearScheduleTypeID: scheduleItem = scheduleTypeFactory.createLinearScheduleItem(); break; default: break; } return scheduleItem; } }

    Read the article

  • Daisy-chaining network switches with multiple cables

    - by user72153
    This might just be the dumbest question you'll ever read, but I digress. Say I have two 100Mbps Ethernet switches with 2 computers on each, connected together by a single cable. This way, the two PCs on each switch share the 100Mbps bandwidth with the others. If I added another cable between the 2 switches, would there be 200Mbps throughput available between the switches? Or am I completely off my rocker? Thanks for the help.

    Read the article

  • OpenVPN Chaining

    - by noderunner
    I'm trying to set up an OpenVPN "chain", similar to what is described here. I have two separate networks, A and B. Each network has an OpenVPN server using a standard "road warrior" or "client/server" approach. A client can connect to either one for access to the hosts/services on that respective network. But server A and B are also connected to each other. The servers on each network have a "site-to-site" connection between the two. What I'm trying to accomplish, is the ability to connect to network A as a client, and then make connections with hosts on network B. I'm using tun/routing for all of the VPN connections. The "chain" looks something like this: [Client] --- [Server A] --- [Server A] --- [Server B] --- [Server B] --- [Host B] (tun0) (tun0) (tun1) (tun0) (eth0) (eth0) The whole idea is that server A should route traffic destined to network B through the "site-to-site" VPN set up on tun1 when a client from tun0 tries to connect. I did this simply by setting up two connection profiles on server A. One profile is a standard server config running on tun0, defining a virtual client network, IP address pool, pushing routes, etc. The other is a client connection to Server B running on tun1. With ip_forwarding enabled, I then simply added a "push route" to the clients advertising a route to network B. On server A, this seems to work when I look at tcpdump output. If I connect as a client, and then ping a host on network B, I can see the traffic getting passed from tun0 to tun1 on Server A: tcpdump -nSi tun1 icmp The weird thing is that I don't see Server B receiving that traffic through the tunnel. It's as if Server A is sending it through the site-to-site connection like it should, but server B is completely ignoring it. When I look for the traffic on Server B, it simply isn't there. A ping from Server A -- Host B works fine. But a ping from a client connected to Server A to host B does not. I'm wondering if Server B is ignoring the traffic because the source IP does not match the client IP pool that it hands out to clients? Does anyone know if I need to do something on Server B in order for it to see the traffic? This is a complicated problem to explain, so thanks if you stuck with me this far.

    Read the article

  • By using " editingStyleForRowAtIndexPath " method , " didSelectRowAtIndexPath " method is not calle

    - by Madan Mohan
    Hi, the delegate method not called -(void)viewWillAppear:(BOOL)animated { [theTableView setEditing:TRUE animated:TRUE]; } -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } by calling the above the methods i will get minus component before each cell in table view. But the below method didSelectRowAtIndexPath is not called and disclouser indicator is not in visible. (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [theTableView deselectRowAtIndexPath:indexPath animated:YES]; ContactEditViewCotroller *contactEditViewCotroller=[[ContactEditViewCotroller alloc]init]; contactEditViewCotroller.isEdit=isEdit; if(isEdit == YES) { for(int i=0; i<=[editObject.contactList count]-1;i++) { if(indexPath.section == i) { appDelegate.isAddInEdit=NO; editcontacts = [editObject.contactList objectAtIndex:i]; contactEditViewCotroller.editcontacts=editcontacts; indexRow=i; } } } else { for(int i=0; i<=[addContactList count]-1;i++) { if(indexPath.section == i) { appDelegate.isAddInEdit=NO; Contacts *obj = [addContactList objectAtIndex:i]; contactEditViewCotroller.addcontacts=obj; } } } [[self navigationController] pushViewController:contactEditViewCotroller animated:YES]; [contactEditViewCotroller release]; }

    Read the article

  • java Finalize method call

    - by Rajesh Kumar J
    The following is my Class code import java.net.*; import java.util.*; import java.sql.*; import org.apache.log4j.*; class Database { private Connection conn; private org.apache.log4j.Logger log ; private static Database dd=new Database(); private Database(){ try{ log= Logger.getLogger(Database.class); Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection("jdbc:mysql://localhost/bc","root","root"); conn.setReadOnly(false); conn.setAutoCommit(false); log.info("Datbase created"); /*Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn=DriverManager.getConnection("jdbc:odbc:rmldsn"); conn.setReadOnly(false); conn.setAutoCommit(false);*/ } catch(Exception e){ log.info("Cant Create Connection"); } } public static Database getDatabase(){ return dd; } public Connection getConnection(){ return conn; } @Override protected void finalize()throws Throwable { try{ conn.close(); Runtime.getRuntime().gc(); log.info("Database Close"); } catch(Exception e){ log.info("Cannot be closed Database"); } finally{ super.finalize(); } } } This can able to Initialize Database Object only through getDatabase() method. The below is the program which uses the single Database connection for the 4 threads. public class Main extends Thread { public static int c=0; public static int start,end; private int lstart,lend; public static Connection conn; public static Database dbase; public Statement stmt,stmtEXE; public ResultSet rst; /** * @param args the command line arguments */ static{ dbase=Database.getDatabase(); conn=dbase.getConnection(); } Main(String s){ super(s); try{ stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); start=end; lstart=start; end=end+5; lend=end; System.out.println("Start -" +lstart +" End-"+lend); } catch(Exception e){ e.printStackTrace(); } } @Override public void run(){ try{ URL url=new URL("http://localhost:8084/TestWeb/"); rst=stmt.executeQuery("SELECT * FROM bc.cdr_calltimestamp limit "+lstart+","+lend); while(rst.next()){ try{ rst.updateInt(2, 1); rst.updateRow(); conn.commit(); HttpURLConnection httpconn=(HttpURLConnection) url.openConnection(); httpconn.setDoInput(true); httpconn.setDoOutput(true); httpconn.setRequestProperty("Content-Type", "text/xml"); //httpconn.connect(); String reqstring="<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"+ "<message><sms type=\"mt\"><destination messageid=\"PS0\"><address><number" + "type=\"international\">"+ rst.getString(1) +"</number></address></destination><source><address>" + "<number type=\"unknown\"/></address></source><rsr type=\"success_failure\"/><ud" + "type=\"text\">Hello World</ud></sms></message>"; httpconn.getOutputStream().write(reqstring.getBytes(), 0, reqstring.length()); byte b[]=new byte[httpconn.getInputStream().available()]; //System.out.println(httpconn.getContentType()); httpconn.getInputStream().read(b); System.out.println(Thread.currentThread().getName()+new String(" Request"+rst.getString(1))); //System.out.println(new String(b)); httpconn.disconnect(); Thread.sleep(100); } catch(Exception e){ e.printStackTrace(); } } System.out.println(Thread.currentThread().getName()+" "+new java.util.Date()); } catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args) throws Exception{ System.out.println(new java.util.Date()); System.out.println("Memory-before "+Runtime.getRuntime().freeMemory()); Thread t1=new Main("T1-"); Thread t2=new Main("T2-"); Thread t3=new Main("T3-"); Thread t4=new Main("T4-"); t1.start(); t2.start(); t3.start(); t4.start(); System.out.println("Memory-after "+Runtime.getRuntime().freeMemory()); } } I need to Close the connection after all the threads gets executed. Is there any good idea to do so. Kindly help me out in getting this work.

    Read the article

  • Should main method be only consists of object creations and method calls?

    - by crucified soul
    A friend of mine told me that, the best practice is class containing main method should be named Main and only contains main method. Also main method should only parse inputs, create other objects and call other methods. The Main class and main method shouldn't do anything else. Basically what he is saying that class containing main method should be like: public class Main { public static void main(String[] args) { //parse inputs //create other objects //call methods } } Is it the best practice?

    Read the article

  • No Method Error Undefined method 'save' for nil:NilClass

    - by BennyB
    I'm getting this error when i try to create a "Lecture" via my Lecture controller's create method. This used to work but i went on to work on other parts of the app & then of course i come back & something is now throwing this error when a user tries to create a Lecture in my app. I'm sure its something small i'm just overlooking (been at it a while & probably need to take a break)...but I'd appreciate if someone could let me know why this is happening...let me know if i need to post anything else...thx! The error I get NoMethodError in LecturesController#create undefined method `save' for nil:NilClass Rails.root: /Users/name/Sites/rails_projects/app_name Application Trace | Framework Trace | Full Trace app/controllers/lectures_controller.rb:13:in `create' My view to create a new Lecture views/lectures/new.html.erb <% provide(:title, 'Start a Lecture') %> <div class="container"> <div class="content-wrapper"> <h1>Create a Lecture</h1> <div class="row"> <div class="span 6 offset3"> <%= form_for(@lecture) do |f| %> <%= render 'shared/error_messages', :object => f.object %> <div class="field"> <%= f.text_field :title, :placeholder => "What will this Lecture be named?" %> <%= f.text_area :content, :placeholder => "Describe this Lecture & what will be learned..." %> </div> <%= f.submit "Create this Lecture", :class => "btn btn-large btn-primary" %> <% end %> </div> </div> </div> </div> Then my controller where its saying the error is coming from controllers/lectures_controller.rb class LecturesController < ApplicationController before_filter :signed_in_user, :only => [:create, :destroy] before_filter :correct_user, :only => :destroy def index end def new @lecture = current_user.lectures.build if signed_in? end def create if @lecture.save flash[:success] = "Lecture created!" redirect_to @lecture else @activity_items = [ ] render 'new' end end def show @lecture = Lecture.find(params[:id]) end def destroy @lecture.destroy redirect_to root_path end private def correct_user @lecture = current_user.lectures.find_by_id(params[:id]) redirect_to root_path if @lecture.nil? end

    Read the article

  • Question regarding the method local innerclasses accesing the local variables of the method

    - by flash
    Hi I was going through the SCJP book about the innerclasses, and found this statement, it goes something like this. "A method local class can only refer to the local variables which are marked final" and in the explanation the reason specified is about the scope and lifetime of the local class object and the local variables on the heap, But I am unable to understand that.am I missing anything here about 'final'??

    Read the article

  • How do I dispatch to a method based on a parameter's runtime type in C# < 4?

    - by Evan Barkley
    I have an object o which guaranteed at runtime to be one of three types A, B, or C, all of which implement a common interface I. I can control I, but not A, B, or C. (Thus I could use an empty marker interface, or somehow take advantage of the similarities in the types by using the interface, but I can't add new methods or change existing ones in the types.) I also have a series of methods MethodA, MethodB, and MethodC. The runtime type of o is looked up and is then used as a parameter to these methods. public void MethodA(A a) { ... } public void MethodB(B b) { ... } public void MethodC(C c) { ... } Using this strategy, right now a check has to be performed on the type of o to determine which method should be invoked. Instead, I would like to simply have three overloaded methods: public void Method(A a) { ... } // these are all overloads of each other public void Method(B b) { ... } public void Method(C c) { ... } Now I'm letting C# do the dispatch instead of doing it manually myself. Can this be done? The naive straightforward approach doesn't work, of course: Cannot resolve method 'Method(object)'. Candidates are: void Method(A) void Method(B) void Method(C)

    Read the article

  • calling Overloaded method from a generic method.

    - by asela38
    How to create a generic method which can call overloaded methods? I tried but it gives a compilation error. Test.java:19: incompatible types found : java.lang.Object required: T T newt = getCloneOf(t); ^ import java.util.*; public class Test { private Object getCloneOf(Object s) { return new Object(); } private String getCloneOf(String s) { return new String(s); } private <T> Set<T> getCloneOf(Set<T> set){ Set<T> newSet = null; if( null != set) { newSet = new HashSet<T>(); for (T t : set) { T newt = getCloneOf(t); newSet.add(newt); } } } }

    Read the article

  • Ruby - Call method passing values of array as each parameter

    - by Markus Orreilly
    I'm currently stuck on this problem. I've hooked into the method_missing function in a class I've made. When a function is called that doesn't exist, I want to call another function I know exists, passing the args array as all of the parameters to the second function. Does anyone know a way to do this? For example, I'd like to do something like this: class Blah def valid_method(p1, p2, p3, opt=false) puts "p1: #{p1}, p2: #{p2}, p3: #{p3}, opt: #{opt.inspect}" end def method_missing(methodname, *args) if methodname.to_s =~ /_with_opt$/ real_method = methodname.to_s.gsub(/_with_opt$/, '') send(real_method, args) # <-- this is the problem end end end b = Blah.new b.valid_method(1,2,3) # output: p1: 1, p2: 2, p3: 3, opt: false b.valid_method_with_opt(2,3,4) # output: p1: 2, p2: 3, p3: 4, opt: true (Oh, and btw, the above example doesn't work for me)

    Read the article

  • objective-c description method

    - by rocity
    Maybe I'm stupid...and this is my first question so forgive me...but when I run this code, I get the following output: (FROG idle:0 animating:0 rect:(null) position:{{1,2}{3,4}} tongue:{5,6}) This is wrong because it seems to be skipping the rect format string and placing everything displaced by one. So idle and animating are what i expect, then rect is skipped, but the result from NSStringFromCGRect(self.rect) is placed into position, then the result for position is pushed to tongue, then tongue is not displayed at all. I'm at a loss. - (NSString *)description{ return [NSString stringWithFormat:@"(FROG idle:%i animating:%i rect:%@ position:%@ tongue:%@)", self.idleTime, self.animating, NSStringFromCGRect(self.rect), NSStringFromCGPoint(self.position), tongue ]; }

    Read the article

  • Passing parameters to web service method in c#

    - by wafa.cs1
    Hello I'm developing an android application .. which will send location data to a web service to store in the server database. In Java: I've used REST protocol so the URI is: HttpPost request = new HttpPost("http://trafficmapsa.com/GService.asmx/GPSdata? lon="+Lon+"&Lat="+Lat+"&speed="+speed); In Asp.net (c#) web service will be: [WebMethod] public CountryName GPSdata(Double Lon, Double Lat, Double speed) { after passing the data from android ..nothing return in back .. and there is no data in the database!! Is there any library missing in the CS file!! I cannot figure out what is the problem.

    Read the article

  • Java synchronized method lock on object, or method?

    - by wuntee
    If I have 2 synchronized methods in the same class, but each accessing different variables, can 2 threads access those 2 methods at the same time? Does the lock occur on the object, or does it get as specific as the variables inside the synchronized method? Example: class x{ private int a; private int b; public synchronized void addA(){ a++; } public synchronized void addB(){ b++; } } Can 2 threads access the same instance of class x performing x.addA() and x.addB() at the same time?

    Read the article

  • Hashing a python method to regenerate output when method is modified

    - by Seth Johnson
    I have a python method that has a deterministic result. It takes a long time to run and generates a large output: def time_consuming_method(): # lots_of_computing_time to come up with the_result return the_result I modify time_consuming_method from time to time, but I would like to avoid having it run again while it's unchanged. [Time_consuming_method only depends on functions that are immutable for the purposes considered here; i.e. it might have functions from Python libraries but not from other pieces of my code that I'd change.] The solution that suggests itself to me is to cache the output and also cache some "hash" of the function. If the hash changes, the function will have been modified, and we have to re-generate the output. Is this possible or a ridiculous idea? If this isn't a terrible idea, is the best implementation to write f = """ def ridiculous_method(): a = # # lots_of_computing_time return a """ , use the hashlib module to compute a hash for f, and use compile or eval to run it as code?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >