• CodeBaker
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hey, sorry if this is a stupid question but I pretty lost with this issue.

 

I have an interface that I was hoping to implement with an anonymous class, but instead I get an unexpected token '{; error.

 

I am unable to find any documentation anywhere saying I am not allowed to do this and I'm able to do this within Java just fine.

 

Any tips if this is even possible would be helpful.

 

 

public with sharing class AnonymousEngine {
	private virtual interface Evaluator<T> {
		boolean expression(T val1, T val2);			
	}

	private class CreateEvaluator{
		private Evaluator<Double> eval;
		private Double number1, number2;
		public CreateEvaluator(Double a, Double b){
			number1 = a;
			number2 = b;
			
			eval = new Evaluator<Double>(){ // unexpected token: '{'
				public boolean expression(Double val1, Double val2){
					return (val1 == val2);
				}
			};
			
		}
		
		public boolean getResults(){
			eval.expression(number1, number2);
		}
		
	}	
}

 

Thanks in advance. 

Hey, sorry if this is a stupid question but I pretty lost with this issue.

 

I have an interface that I was hoping to implement with an anonymous class, but instead I get an unexpected token '{; error.

 

I am unable to find any documentation anywhere saying I am not allowed to do this and I'm able to do this within Java just fine.

 

Any tips if this is even possible would be helpful.

 

 

public with sharing class AnonymousEngine {
	private virtual interface Evaluator<T> {
		boolean expression(T val1, T val2);			
	}

	private class CreateEvaluator{
		private Evaluator<Double> eval;
		private Double number1, number2;
		public CreateEvaluator(Double a, Double b){
			number1 = a;
			number2 = b;
			
			eval = new Evaluator<Double>(){ // unexpected token: '{'
				public boolean expression(Double val1, Double val2){
					return (val1 == val2);
				}
			};
			
		}
		
		public boolean getResults(){
			eval.expression(number1, number2);
		}
		
	}	
}

 

Thanks in advance. 

I am writing a custom Class. It has a bunch of properties. In one constructor, when I pass one argument, an ID. It fills 1/3 of the properties. in another constructor, I pass a record ID as well as an associated record's ID as arguments. The constructor fills all the properties.

My question is this: Is there a way in the constructor with two arguments, to just call the one argument constructor and thus have 1/3 of the properties filled for free? As of this writing I am accomplishing this by instantiating a new instance of the class, and using dot notation to manually fill the properties that the one argument constructor filled. This seems rather pointless and redundant.

 

Here is my code as is:

public class MyFloor2{
        //Properties
        public floor__c                   floor     {get; set;}
        public attachment                 a         {get; set;}
        public string                     floorplan {get; set;}
        public blob                       file      {get; set;}
        public boolean                    noFA      {get; set;}
        public boolean                    noFX      {get; set;}
        public boolean                    noSH      {get; set;}
        public boolean                    noFP      {get; set;}
        public account_c__c               account   {get; set;}
        public list<FA_Device__c>         fadevices {get; set;}
        public list<FA_Result__c>         faresults {get; set;}
        public list<FX_Result__c>         fxresults {get; set;}
        public list<SH_Result__c>         shresults {get; set;}
        public list<SObject>              results   {get; set;}
        public list<floor_tenant__c>      tenants   {get; set;}
        
        //Constructors         
        public MyFloor2(){
        }
        
        public MyFloor2(string id){
            //This code utilizes a class I wrote that mimics the SQL Select * functionality. Suffice to say it represents a Select All query 
            string floorfields = new selectall('floor__c').allfields;
            string fadevicequery = 'Select '+ new selectall('fa_device__c').allfields +' from fa_devices__r order by device_number__c';
            string tenantquery   = 'Select '+ new selectall('floor_tenant__c').allfields +' from floor_tenants__r order by name';
            string floorquery ='Select '+floorfields+', ('+fadevicequery+'), ('+tenantquery+'), (Select Id From Attachments Where name = \'floorplan.jpg\') From floor__c where id=:id';
            
            floor = database.query(floorquery);
            string aid = floor.account__c;
            account = database.query(new selectall('account_c__c').soql+' where id=:aid');
            fadevices = floor.fa_devices__r;
            noFA = fadevices.isempty();
            tenants = floor.floor_tenants__r;
            if(floor.Attachments.isempty()){
                noFP = true;
            }else{
                a = floor.Attachments;
                floorplan = a.id;                
            }
        }
        
        public MyFloor2(string id, string sid){
            //This code utilizes a class I wrote that mimics the SQL Select * functionality. Suffice to say it represents a Select All query            
            string faresultquery = 'Select '+ new selectall('fa_result__c').allfields +' from fa_results1__r where system_inspection__c =:sid order by device_number__c';
            string fxresultquery = 'Select '+ new selectall('fx_result__c').allfields +' from fx_results__r where system_inspection__c =:sid order by number__c';
            string shresultquery = 'Select '+ new selectall('sh_result__c').allfields +' from sh_results__r where system_inspection__c =:sid order by device_number__c';
            string floor ='Select ('+faresultquery+'), ('+fxresultquery+'), ('+shresultquery+') From floor__c where id=:id';
            MyFloor2 myf2 = new MyFloor2(id);
            floor__c f = database.query(floor);
           
            this.floor = myf2.floor;
            this.fadevices = myf2.fadevices;
            this.tenants = myf2.tenants;
            this.floorplan = myf2.floorplan;
            this.account = myf2.account;
            
            this.faresults = f.fa_results1__r;
            this.fxresults = f.fx_results__r;
            this.shresults = f.sh_results__r;
            this.noFA = this.faresults.isempty();
            this.noFX = this.fxresults.isempty();
            this.noSH = this.shresults.isempty();
        }
        //Methods
        //....